Dear useRs,

I recently posted here 
(https://stat.ethz.ch/pipermail/r-help/2015-July/430223.html) a query regarding 
customizing panel functions for lattice::xyplot.  I received some helpful 
replies offline and while I learned some things, they did not get at my issue.  
However there was a consensus that my original example was complex and hard to 
understand, so I want to revisit the issue with a very simple example.

Let's look at the teeth data in nlme::Orthodont.

    require(lattice)
    require(nlme)
    ?Orthodont

One way to display this data is to condition on the Sex of the Subject, and 
plot distance as function of age, grouped by Subject.  This plot distinguishes 
the Sex factor by making two panels, one for each Sex.

    xyplot(distance ~ age | Sex, data=Orthodont, groups=Subject, type='b')

The goal I have is to not use conditioning to differentiate data between the 
Sexes, but rather separate graphical parameters (I want to use other 
conditioning variables...).  The problem is normally graphical parameters are 
associated with the grouping variable, and I want to keep the grouping variable 
but use another variable (here Sex) to be distinguished graphically.  I can 
remove the conditioning as follows; the graphical parameters are mapped onto 
the grouping variable as expected:

    xyplot(distance ~ age, data=Orthodont, groups=Subject, type='b')

This is what I want, except I want only two colors, one for the Male Subjects, 
and one for the Female ones.  It seems the subscripts argument to panel 
functions is designed for this type of thing.  Based on the example from Figure 
5.4 in Sarkar's lattice book, I thought the following would work:

    xyplot(distance ~ age, data=Orthodont, groups=Subject, type='b',
             # passing the vector of colors
           Cols = Orthodont[['Sex']] ,
           panel = function(x, y, ..., groups, subscripts, Cols){
                            panel.xyplot(x, y, ..., groups=groups, 
subscripts=subscripts,
                                         col.line=Cols[subscripts], 
col.symbol=Cols[subscripts]
                                        )
                           }
          )

But all the Subjects are plotted with the same color.

How can I arrange to have different graphical parameters for each level of Sex, 
without using Sex as either grouping or conditioning variable?

[I am using R version 3.2.1 (release version), revision 68531, and version 
0.20-31 of lattice.]

Thanks,
John

John Szumiloski, Ph.D.
Principal Scientist, Statistician
Analytical and Bioanalytical Development
NBR105-1-1411

Bristol-Myers Squibb
P.O. Box 191
1 Squibb Drive
New Brunswick, NJ
08903-0191

(732) 227-7167



________________________________
 This message (including any attachments) may contain co...{{dropped:8}}

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to