[R] panel.groups: use group.number to define colors

Bert Gunter gunter.berton at gene.com
Tue Oct 7 19:25:40 CEST 2008


Not exactly sure what you want to do, but ...

In your example, you do not need groups, since the color doesn't change
within the levels of the conditioning variable (fact). Hence you can use the
panel.number() function to choose the plotting color of each panel, like
this:

## .. continuing with your example 

 myColors <- rep(c(2,4),2)

 xyplot(y ~ x | fact,  data = my.df,
 	      panel =  function(...){
            panel.xyplot(...,col=myColors[panel.number()])
         }
 	  )

If you actually **need** groups (to color different subsets of the data
within a panel differently). it does get a bit more complicated.
Incidentally, note that col is already a formal argument of panel.superpose
and was therefore  picked up in the ... argument of the panel.groups
function -- that's why you got the error you did when you repeated col
explicitly in the panel.xyplot call. By default, it's values are those of
trellis.par.get("superpose.symbol") I believe. Also, group.number appears to
be undefined in your code.

HTH

Cheers,
Bert Gunter



More information about the R-help mailing list