Skip to content

all (y,x) data in one plot

3 messages · Judy Chung, PIKAL Petr, Sundar Dorai-Raj

#
Dear R users:
   I want to plot all the Y1 vs. X1 which in list "coffee" together,
in the same plot.
[[1]]
  Y1        X1
1  0.0 10.006306
2  0.5  9.433443
3  1.0  8.893405
4  2.0  7.904274

[[2]]
  Y1        X1
1  0.0 10.015972
2  0.5  9.460064
3  1.0  8.935039
4  2.0  7.970755

[[3]]
  Y1       X1
1  0.0 9.985741
2  0.5 9.552583
3  1.0 9.138239
4  2.0 8.362664

[[4]]
.......

[[5]]
.......
.....
.......
Because I am a newbie in R, so I just can use the above method to
solve the problem.
If there is a smarter way to this.
Thanks for any help.
#
Hi

yesterday was answered similar list question (do.call is your friend)

lll<- list(data.frame(a=1:10,b=rnorm(10)), 
data.frame(a=1:9,b=rnorm(9)+5))
mat <- sapply(lll, dim)
plot(do.call("rbind",lll), pch=rep(1:dim(mat)[2], 
times=as.numeric(mat[1,])))

HTH
Petr
On 8 Dec 2005 at 17:59, Judy Chung wrote:
Date sent:      	Thu, 8 Dec 2005 17:59:31 +0800
From:           	Judy Chung <cp3942 at gmail.com>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] all (y,x) data in one plot
Petr Pikal
petr.pikal at precheza.cz
#
Or use lattice:

x <- list(data.frame(a = 1:10, b = rnorm(10)),
           data.frame(a = 1:9, b = rnorm(9) + 5))
## create grouping variable
g <- rep(seq(along = x), sapply(x, nrow))
## if `x' has names then replace by
## g <- rep(names(x), sapply(x, nrow))
z <- cbind(do.call("rbind", x), g = g)

library(lattice)
trellis.device(theme = col.whitebg())
xyplot(b ~ a, z, groups = g, auto.key = list(space = "right"))

--sundar
Petr Pikal wrote: