[R] Plotting the occassional second label

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Apr 10 11:46:13 CEST 2005


"Lisbeth Riis" <lriis at scarabconsult.com> writes:

> Dear useRs,
> 
> I'm trying to plot spray quantities against dates, and label the points 
> on the plot. Basically quite simple, but sometimes two chemicals have 
> been used and are listed in separate rows in the table as below; then 
> the labels are written on top of each other.
> 
> > spray
>    SprayDate          PD            Trt Qwater  Qai
> 1 2005-03-09 Spidermites        Pegasus   1300 1.04
> 2 2005-03-10     Powdery            MKP    800 0.40
> 3 2005-03-10     Powdery  Nimrod 250 EC    800 2.40
> 4 2005-03-12 Spidermites        Pegasus   1300 1.04
> 5 2005-03-16 Spidermites        Pegasus   1300 1.04
> 6 2005-03-17     Powdery   Stroby 50 WG    800 0.40
> 7 2005-03-21 Spidermites Dynamec 1.8 EC   1250 0.62
> 8 2005-03-21 Spidermites   Apollo 50 SC   1250 0.62
> 9 2005-03-30  Whiteflies        Pegasus   1000 0.60
> 
> I came up with the work around below which gave me my plot for some of 
> the data (despite warnings). The idea was to split the second chemical for each date into 
> a separate file and plot the text a little higher:
> 
> > spray1 <- spray[spray$PD=="Spidermites", ]
> > spray2 <- spray1[spray1$SprayDate==unique(spray1$SprayDate), ]
> Warning message: 
> longer object length
>         is not a multiple of shorter object length in: spray1$SprayDate == unique(spray1$SprayDate) 

I don't think this does what I think you think it does...

Consider

> x <- c(1,1,2,3)
> x == unique(x)
[1]  TRUE FALSE FALSE FALSE
Warning message:
longer object length
        is not a multiple of shorter object length in: x == unique(x)

unique(x) is c(1,2,3) so you end up with c(1,1,2,3)==c(1,2,3,1)

Were you perhaps intending

> !duplicated(x)
[1]  TRUE FALSE  TRUE  TRUE

?

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list