On 2010-12-11 16:47, Felix Andrews wrote:
On 12 December 2010 00:08, Peter Ehlers<ehl...@ucalgary.ca>  wrote:

[...snip...]

The idea is the same: you need to get your data
into "long" format with a grouping variable and
then use the 'groups' argument to xyplot.
Here's fake data frame (you should have provided one):

  DF<- data.frame(y1 = rnorm(30),
                  y2 = rnorm(30) + 2,
                  x  = rep(1:10, 3),
               sites = gl(3, 10, lab=LETTERS[1:3]))

## Use the reshape2 package to melt the data:
## (or use reshape() in base R)
  require(reshape2)
  DF1<- melt(DF, measure.vars = c('y1', 'y2'),
             variable.name = 'grp', value.name = 'y')

## and plot:
  require(lattice)
  p<- xyplot( y ~ x | sites, data = DF1, groups = grp,
             col = c("red", "blue"), type = "b")
  print(p)

Peter Ehlers


By the way, in this particular case there is a shortcut which does the
reshaping internally:

xyplot(y1 + y2 ~ x | sites, DF, type = "b")

Right; thanks for the reminder, Felix. I keep forgetting
about that mainly because I almost always need 'long' data.

Peter Ehlers

[...snip...]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to