Skip to content
Back to formatted view

Raw Message

Message-ID: <5934ae5705041014192efba04b@mail.gmail.com>
Date: 2005-04-10T21:19:21Z
From: Rich FitzJohn
Subject: Plotting the occassional second label
In-Reply-To: <000a01c53da6$cf045400$9e4fcac3@Lisbeth>

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