Skip to content
Prev 67350 / 398525 Next

Plotting the occassional second label

Another option is to combine the sprays used as a single string, and
plot that directly, rather than subsetting the data.  This has the
advantages of not having to worry about how much to offset the second
label by, and should also work if you got more than two sprays per
day.

spray$SprayDate <- as.Date(spray$SprayDate)
spray.sub <- spray[spray$PD=="Spidermites",]

## Collapse, so there is only a single row per date
spray.col <- spray.sub[unique(tapply(spray.sub$SprayDate,
                                     spray.sub$SprayDate)),]

## And paste together any treatments used on a single day, separated
## by a newline
txt <- tapply(spray.sub$Trt, spray.sub$SprayDate, paste,
              collapse="\n") 

plot(spray.col$SprayDate, spray.col$Qwater,
     xlim=c(as.Date("2005-03-08"), as.Date("2005-03-24")),
     ylim=c(0,1500))
text(spray.col$SprayDate, spray.col$Qwater, txt, pos=4, srt=45)

If you wanted the order of the chemicals used changed, you could
insert a new function into the tapply() call, e.g.
tapply(spray.sub$Trt, spray.sub$SprayDate,
       function(x) paste(rev(x), collapse="\n"))

Cheers,
Rich
On Apr 10, 2005 8:24 PM, Lisbeth Riis <lriis at scarabconsult.com> wrote:
...