[R] Plotting the occassional second label
Rich FitzJohn
rich.fitzjohn at gmail.com
Sun Apr 10 23:19:21 CEST 2005
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:
> 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.
...
> Does anyone have a better way of splitting the second reading for each
> date off, or another way of printing two labels for one plotted point?
--
Rich FitzJohn
rich.fitzjohn <at> gmail.com | http://homepages.paradise.net.nz/richa183
You are in a maze of twisty little functions, all alike
More information about the R-help
mailing list