Skip to content

Plotting the occassional second label

3 messages · Lisbeth Riis, Peter Dalgaard, Rich FitzJohn

#
"Lisbeth Riis" <lriis at scarabconsult.com> writes:
I don't think this does what I think you think it does...

Consider
[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
[1]  TRUE FALSE  TRUE  TRUE

?
#
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:
...