On Thu, Oct 8, 2009 at 8:11 PM, John Field <johnfi...@ozemail.com.au> wrote: > Dear R list, > > The code below puts qq-plots for two of three groups on the one plot. > However the legend includes all three groups, ie the auto.key ignores the > subset instruction. Is there an easy way to get around this, so that only > those groups plotted are included in the legend? > > y1<-rnorm(100); y2<-rnorm(100)+1; y3<-rnorm(100)+2; y<-c(y1,y2,y3) > fact=factor(c(rep(1,100),rep(2,100),rep(3,100))) > require(lattice) > qqmath(~y,groups=fact,auto.key=list(corner=c(0,1)),subset=fact!=2)
The subsetting of groups happens independently in each panel. As there's no guarantee in general that the subset will have the same non-empty set of levels in each panel, the only solution (with a common legend) is to keep all the levels. To drop unused levels in groups, you need to subset your data beforehand. For example, df <- data.frame(y=c(y1,y2,y3), fact=factor(c(rep(1,100),rep(2,100),rep(3,100)))) qqmath(~y, data=subset(df, fact!=2), groups=fact[drop=TRUE],auto.key=list(corner=c(0,1))) -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.