[R] lattice: two grouping variables, one controls 'col', the other 'pch'

hadley wickham h.wickham at gmail.com
Tue Jan 30 19:05:07 CET 2007


On 1/28/07, Benjamin Tyner <btyner at stat.purdue.edu> wrote:
> Say I have
>
> library(lattice)
>
> x<-runif(256)
> y<-runif(256)
> f<-gl(16,16)
> g1<-rep(1:4,each=64)
> g2<-rep(1:4,times=64)
>
> plot<-xyplot(y~x|f,
>              groups=g1,
>              pch=as.character(1:4),
>              panel=function(x,y,subscripts,groups,...){
>                    panel.superpose(x,y,subscripts,groups,...)
>              })
>
> print(plot)
>
> Currently, both color and plotting symbol change with the grouping
> variable g1. What is the best way to have color change with g1, but
> plotting symbol change with g2 (or vice versa)?

Another option is to use ggplot:

install.packages("ggplot")
library(ggplot)
qplot(x, y, facet=. ~ f, size=g1, colour=g2)



More information about the R-help mailing list