[R] lattice: How to plot an xyplot (with panels) without using a dataframe?

Marius Hofert m_hofert at web.de
Wed May 19 14:15:19 CEST 2010


Dear R users,

Is it possible to draw an xyplot (example below) without having to build a dataframe?
For example: I have some data in matrix-form. Usually, the first column is the x-value, the columns 2 and 3 are y-values. I would then like to plot 2 panels where the first panel draws the second column against the first column and the second panel draws the third column against the first column. It seems "tedious" to construct a dataframe just for the plots.

Cheers,

Marius

library(lattice)

x <- 1:10
y <- cbind(x,-x) # 2-column matrix
p <- cbind(rep(1,10),rep(2,10)) # "panel" matrix

xyplot(y~x|p) # does not work; can this be fixed (without the use of a dataframe)?


More information about the R-help mailing list