Benjamin Tyner
2007-Jan-29 04:41 UTC
[R] lattice: two grouping variables, one controls 'col', the other 'pch'
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)? Thanks, Ben
Gabor Grothendieck
2007-Jan-29 05:18 UTC
[R] lattice: two grouping variables, one controls 'col', the other 'pch'
Try: xyplot(y ~ x | f, pch = g1, col = g2, panel = function(x, y, subscripts, ..., pch, col) panel.xyplot(x, y, ..., col = col[subscripts], pch = pch[subscripts]) ) 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)? > > Thanks, > Ben > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >
hadley wickham
2007-Jan-30 18:05 UTC
[R] lattice: two grouping variables, one controls 'col', the other 'pch'
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)
Apparently Analagous Threads
- lattice and several groups
- Lattice: Superpose bwplot and dotplot [newbie question]
- custom strip in lattice ignoring plotmath expressions for all but style = 1 (PR#8733)
- how to output profile plots for groups using lattice package
- lattice dotplot and graphic devices on Windows