Re: [R] lattice code to plot columns over another variable

2010-04-23 Thread Deepayan Sarkar
On Tue, Apr 20, 2010 at 9:03 AM, Rajarshi Guha  wrote:
> Hi, I've been struggling with a lattice visualiation. I have a
> data.frame with 4 columns. What I'd like to have is a set of 3 panels.
> Ecah panel will have the first column plotted against serial number
> and then will superimpose the relevant column. My non-lattice version
> is as follows:
>
> x <- data.frame( ... )
> par(mfrow=c(3,1))
> for (i in 2:4) {
>  plot(x[,1])
>  points(x[,i])
> }
>
> Any suggestions as to how I could convert this to a lattice version
> would be much appreciated

Easiest to think of this as a data reshaping problem.

x <- as.data.frame(matrix(rnorm(4 * 20), 20, 4))

n <- nrow(x)
y <- data.frame(i = seq_len(n), y1 = x[,1],
y2 = unlist(x[-1]),
g = gl(ncol(x) - 1, n))
xyplot(y2 + y1 ~ i | g, data = y, type = "l")

-Deepayan

__
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.


[R] lattice code to plot columns over another variable

2010-04-20 Thread Rajarshi Guha
Hi, I've been struggling with a lattice visualiation. I have a
data.frame with 4 columns. What I'd like to have is a set of 3 panels.
Ecah panel will have the first column plotted against serial number
and then will superimpose the relevant column. My non-lattice version
is as follows:

x <- data.frame( ... )
par(mfrow=c(3,1))
for (i in 2:4) {
  plot(x[,1])
  points(x[,i])
}

Any suggestions as to how I could convert this to a lattice version
would be much appreciated

Thanks,

-- 
Rajarshi Guha
NIH Chemical Genomics Center

__
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.