[R] more than one level of grouping in xyplot

Deepayan Sarkar deepayan at stat.wisc.edu
Thu Nov 21 22:01:30 CET 2002

On Thursday 21 November 2002 07:40 am, Guazzetti Stefano wrote:
> Dear listers,
> Let use say that I want to display the Pixel dataset (in the NLME library)
> xyplot(pixel~day|Dog, groups=Side, data=Pixel, panel=panel.superpose,
> panel.groups=panel.xyplot, type="b", pch=16) (I know, there are better
> examples, ...)
> Now, how could I change the colours of the symbols accordingly to another
> factor changing within subject and side form time to time? (let us say
> Pixel$Fever<-sample(rep(0:1,51)))

You cannot, at least not directly. The usual trick is to define your groups 
variable according to what you want. In this case, maybe something like

newG <- paste(as.character(Pixel$Side), as.character(Pixel$Fever))

will work as the groups argument. If the resulting color scheme is not to your 
liking, you could specify a col vector that would correspond to 

In this case however, you seem to want the lines to be drawn according to one 
grouping, and the points to be colored according to another. This would not 
be that simple. But it could be done if you modify panel.superpose slightly 
to accept another grouping variable (hint: you have to use the subscripts 
argument, and probably use the fact that panel.xyplot accepts a vector 'col' 


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list