Many thanks to Naomi Robbins, Christopher Green, Brad Biggerstaff and
Andreas Kraus for timely and useful responses to my question. A summary
of their responses follows:
Naomi Robbins wrote:
> Suppose you had only one unit. Can you draw what you want
> in that case? If so, put those commands in a panel function for
> your trellis plot and then the trellis commands take care of the
> framework; i.e., the rows, cols, and layout.
Christopher G. Green wrote:
> xyplot with panel=panel.superpose and a groups argument can help you
> put multiple series on each panel. Don't know about the error
> bars...maybe you need a custom panel function.
Brad Biggerstaff wrote:
> Look at the xYplot function (using Cbind) in the Hmisc library (and
its help page),
> distributed with S-Plus (and available in R). Also, to have multiple
lines per panel, look
> into using the groups parameter with panel.superpose or a custom panel
function.
Andreas Krause wrote:
not all details are given to give a precise answer, but here is a
generic answer.
Combine your 3 time series into one and add an indicator variable
similar to this:
value time dataset
11 0 1
where dataset is either 1, 2, or 3 to indicate the original data set.
Then you can do anything you want if you do something like this:
xyplot(value ~ time | z, data=x, alldata=x,
colors=c("red", "green", "blue", "orange"),
panel=function(x, y, ..., subscripts, alldata, colors=1:99)
{
this.data <- alldata[subscripts, ...]
# gets you the data for the current panel
# Now you can do whatever you want inside the panel, for example:
for(index in unique(this.data$dataset))
{
data.sub <- this.data[this.data$dataset==index, ] # get one
series
panel.lines(data.sub$x, data.sub$y, col=colors[index]) # lines
}
)
# The trick is to just pass the entire data set to the panel function
and then extract the ones you want.
Note that you can calculate standard errors beforehand,
sdv <- aggregate(list("sdv"=x[, "value"]), x[, c("time", "dataset")],
function(x) { x <- x[!is.na(x)]; return(sqrt(var(x))/length(x))
} )
x2 <- merge(x, sdv, all=TRUE)
or you do the calculation inside the panel function (!).
An extended example of such customization is shown in our book, The
Basics of S-Plus, in the exercises and solutions of the chapter on
"Trellis Graphics".
-----Original Message-----
From: Huso, Manuela
Sent: Monday, March 30, 2009 10:26 AM
To: s-news@lists.biostat.wustl.edu
Subject: Trellis help
Hello, all,
I would like to make a trellis plot that has 3 lines (plus error bars
at certain points in each of the panels). I have not seen an example of
this... Every example I have seen has only one line per plot. I have
the equivalent of 3 time series measured on each experimental unit, and
I have 18 units, so I am looking to produce a panel of 6 rows X 3
columns, each with 3 lines (with vertical error bars at about 7
locations along each line). Can anyone point me to a parallel example,
please?
Many thanks in advance!
Manuela
>::<>::<>::<>::<>::<>::<>::<>::<>::<>::<>::<
Manuela Huso
Consulting Statistician
Department of Forest Ecosystems and Society 201H Richardson Hall Oregon
State University
Corvallis, OR 97331
ph: 541.737.6232
fx: 541.737.1393
|