Re: [R] Plotting the occassional second label

From: Rich FitzJohn <rich.fitzjohn_at_gmail.com>
Date: Mon 11 Apr 2005 - 07:19:21 EST

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@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Apr 11 07:26:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:06 EST