Hi! I would like to know, how do you plot more than one data series when using "coplot"? I think I know the answer if "plot" is being used: x <- 1:10 y <- 1:10 y2 <- 1:10* 1.1 plot ( y ~ x, type="n" ) points( y ~ x, type = "b", col = "red" ) # plot the points and lines for the first series points( y2 ~ x, type = "b", col = "blue" ) # plot the points and lines for the second series But how should it be done with "coplot"? If I make my question more concrete: df <- data.frame( x=x, y=y, y2=y2, v=c("a","b")) # using the vectors above coplot( df$y~df$x | df$v, type="b", col="red") # gives me a coplot of y ~ x How do I now put points and lines for y2 on the same graphs? Thank you for your thoughts, Matthew
On Friday 04 June 2004 23:04, Matthew Walker wrote:> Hi! > > I would like to know, how do you plot more than one data series when > using "coplot"? > > I think I know the answer if "plot" is being used: > x <- 1:10 > y <- 1:10 > y2 <- 1:10* 1.1 > plot ( y ~ x, type="n" ) > points( y ~ x, type = "b", col = "red" ) # plot the points and lines > for the first series > points( y2 ~ x, type = "b", col = "blue" ) # plot the points and > lines for the second series > > But how should it be done with "coplot"? > > If I make my question more concrete: > df <- data.frame( x=x, y=y, y2=y2, v=c("a","b")) # using the vectors > above coplot( df$y~df$x | df$v, type="b", col="red") # gives me a > coplot of y ~ x > > How do I now put points and lines for y2 on the same graphs?Don't know about coplot, but with xyplot from the lattice package (which one might consider to be a refined version of coplot) you could do: xyplot(y + y2 ~ x, df, type = 'b', col = c('blue', 'red')) Deepayan
Hi Matthew Walker wrote:> Hi! > > I would like to know, how do you plot more than one data series when > using "coplot"? > > I think I know the answer if "plot" is being used: > x <- 1:10 > y <- 1:10 > y2 <- 1:10* 1.1 > plot ( y ~ x, type="n" ) > points( y ~ x, type = "b", col = "red" ) # plot the points and lines > for the first series > points( y2 ~ x, type = "b", col = "blue" ) # plot the points and lines > for the second series > > But how should it be done with "coplot"? > > If I make my question more concrete: > df <- data.frame( x=x, y=y, y2=y2, v=c("a","b")) # using the vectors above > coplot( df$y~df$x | df$v, type="b", col="red") # gives me a coplot of y > ~ x > > How do I now put points and lines for y2 on the same graphs?Use the panel argument, as below ... x <- 1:10 y <- 1:10 y2 <- 1:10* 1.1 df <- data.frame( x=x, y=y, y2=y2, v=c("a","b")) # using the vectors above coplot( df$y~df$x | df$v, type="b", col="red", subscripts=TRUE, panel=function(x, y, subscripts, ...) { points(x, y, ...) points(x, y2[subscripts], ...)}) Paul -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/