[R] all (y,x) data in one plot
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Thu Dec 8 14:45:33 CET 2005
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:
> 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
>
>
>>Dear R users:
>> I want to plot all the Y1 vs. X1 which in list "coffee" together,
>>in the same plot. > coffee [[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]]
>>.......
>>
>>
>>>x1<-coffee[[1]]$Y1
>>>y1<-coffee[[1]]$X1
>>>x2<-coffee[[2]]$Y1
>>>y2<-coffee[[2]]$X1
>>>x3<-coffee[[3]]$Y1
>>>y3<-coffee[[3]]$X1
>>
>>.....
>>
>>>plot(y1~x1)
>>>points(y2~x2)
>>>points(y3~x3)
>>
>>.......
>>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.
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide!
>>http://www.R-project.org/posting-guide.html
>
>
> Petr Pikal
> petr.pikal at precheza.cz
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list