Timothy W. Hilton
2015-Jan-27 21:55 UTC
[R] panel.xyplot and panel.loess using two different groupings
Thanks, Bert, for the reply. This is very helpful. I have to admit
I've read the docs for the panel and panel.groups arguments before and
gotten myself pretty confused. Your small example is very helpful.
One more question for the list...
Bert's panel.loess col='darkblue' argument is being overridden by my
call to par.settings=mytheme, which I've defined like this (using the
RColorBrewer library):
pal <- brewer.pal(length(levels(light_data[['species']])),
'Dark2')
mytheme <- standard.theme("pdf")
mytheme[['superpose.symbol']][['pch']] <- c(15,16,17,3,4)
mytheme[['superpose.symbol']][['col']] <- pal
I've not been able to figure out which trellis.par.get() setting
controls the loess line colors, so I've not been able to set those in
the theme. Similarly, I've not been able to pass a line color argument
to loess that doesn't get clobbered by the theme. Is this possible?
Thanks,
-Tim
On Tue, Jan 2015, 27 at 11:13:51AM -0800, Bert Gunter
wrote:> Learn to use custom panel functions to give you the flexibility and
> features you require.
>
> In this case, you want something like:
>
> xyplot(LRU~PAR|C3C4, groups = species,
> panel= function(x,y,...){ ## custom panel function to add an
> overall loess line
> panel.superpose(x,y,...)
> panel.loess(x,y,col="darkblue",...)
> },
> panel.groups = function(x,y,...){
> panel.xyplot(x,y,...)
> panel.loess(x,y,...)
> }
> ## plus any other key and plot options
> )
>
>
> Note that this could fail if groups have too few points to fit a loess
> curve, so you might want to add checks in the panel.groups function
> for this.
>
>
> HTH.
>
>
> -- Bert
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 467-7374
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
> Clifford Stoll
>
>
>
>
> On Tue, Jan 27, 2015 at 10:19 AM, Timothy W. Hilton
> <thilton at ucmerced.edu> wrote:
> > Hello,
> >
> > I have a dataset consisting of four variables: species (factor, five
> > levels), C3C4 (factor, two levels), and numeric variables PAR and LRU.
> > I wish to produce a scatter plot of PAR vs LRU where (1) each species
> > has a unique symbol and color (2) there is an overlaid loess line that
> > is calculated for each C3C4 level. The following code produces a nice
> > plot where each species has its own loess curve, but I'm
struggling for
> > the syntax to produce a single loess curve for all the points in each
of
> > the two plots:
> >
> > xy <- xyplot(LRU~PAR|C3C4, data=light_data, groups=species,
> > panel=panel.superpose,
> > auto.key=TRUE,
> > col.line=pal,
> > par.settings=mytheme,
> > panel.groups=function(x, y, ...){
> > panel.xyplot(x, y, ...)
> > panel.loess(x, y, ...)})
> >
> > Any help much appreciated. Thanks!
> > Tim
> >
> > --
> >
> > Timothy W. Hilton
> > Assistant Project Scientist
> > Sierra Nevada Research Institute
> > University of California, Merced
> > thilton at ucmerced.edu
> >
> > ______________________________________________
> > R-help at 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.
Bert Gunter
2015-Jan-27 22:11 UTC
[R] panel.xyplot and panel.loess using two different groupings
1. The trellis.par.get$superpose.line list controls the loess line
appearance, I believe (check this!)
2. To control the overall loess curve in the panel, call it without
the "..." arguments, e.g
panel.loess(x,y, col.line="darkblue")
You may have to modify argument lists appropriately if you want to
control the loess smoothing parameters in the xyplot call. The problem
is to avoid replicating parameter names that are passed in the "..."
argument with ones that you explicitly call (e.g. col.line above).
This can get a bit tricky.* If you're going to use lattice regularly
(which I recommend -- or ggplot; both are much more powerful and
flexible interfaces than the original base plotting capabilities,
IMHO), I would suggest getting your hands on Deepayan's book in which
these niceties are more fully explained.
*Also check out the latticeExtra package, as it provides a ggplot-like
syntax ("+") and facilities to handle duplicated parameters in
situations like this.
Cheers,
Bert
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Tue, Jan 27, 2015 at 1:55 PM, Timothy W. Hilton <thilton at
ucmerced.edu> wrote:> Thanks, Bert, for the reply. This is very helpful. I have to admit
> I've read the docs for the panel and panel.groups arguments before and
> gotten myself pretty confused. Your small example is very helpful.
>
> One more question for the list...
>
> Bert's panel.loess col='darkblue' argument is being overridden
by my
> call to par.settings=mytheme, which I've defined like this (using the
> RColorBrewer library):
>
> pal <- brewer.pal(length(levels(light_data[['species']])),
'Dark2')
> mytheme <- standard.theme("pdf")
> mytheme[['superpose.symbol']][['pch']] <-
c(15,16,17,3,4)
> mytheme[['superpose.symbol']][['col']] <- pal
>
> I've not been able to figure out which trellis.par.get() setting
> controls the loess line colors, so I've not been able to set those in
> the theme. Similarly, I've not been able to pass a line color argument
> to loess that doesn't get clobbered by the theme. Is this possible?
>
> Thanks,
> -Tim
>
> On Tue, Jan 2015, 27 at 11:13:51AM -0800, Bert Gunter wrote:
>> Learn to use custom panel functions to give you the flexibility and
>> features you require.
>>
>> In this case, you want something like:
>>
>> xyplot(LRU~PAR|C3C4, groups = species,
>> panel= function(x,y,...){ ## custom panel function to add an
>> overall loess line
>> panel.superpose(x,y,...)
>> panel.loess(x,y,col="darkblue",...)
>> },
>> panel.groups = function(x,y,...){
>> panel.xyplot(x,y,...)
>> panel.loess(x,y,...)
>> }
>> ## plus any other key and plot options
>> )
>>
>>
>> Note that this could fail if groups have too few points to fit a loess
>> curve, so you might want to add checks in the panel.groups function
>> for this.
>>
>>
>> HTH.
>>
>>
>> -- Bert
>>
>> Bert Gunter
>> Genentech Nonclinical Biostatistics
>> (650) 467-7374
>>
>> "Data is not information. Information is not knowledge. And
knowledge
>> is certainly not wisdom."
>> Clifford Stoll
>>
>>
>>
>>
>> On Tue, Jan 27, 2015 at 10:19 AM, Timothy W. Hilton
>> <thilton at ucmerced.edu> wrote:
>> > Hello,
>> >
>> > I have a dataset consisting of four variables: species (factor,
five
>> > levels), C3C4 (factor, two levels), and numeric variables PAR and
LRU.
>> > I wish to produce a scatter plot of PAR vs LRU where (1) each
species
>> > has a unique symbol and color (2) there is an overlaid loess line
that
>> > is calculated for each C3C4 level. The following code produces a
nice
>> > plot where each species has its own loess curve, but I'm
struggling for
>> > the syntax to produce a single loess curve for all the points in
each of
>> > the two plots:
>> >
>> > xy <- xyplot(LRU~PAR|C3C4, data=light_data, groups=species,
>> > panel=panel.superpose,
>> > auto.key=TRUE,
>> > col.line=pal,
>> > par.settings=mytheme,
>> > panel.groups=function(x, y, ...){
>> > panel.xyplot(x, y, ...)
>> > panel.loess(x, y, ...)})
>> >
>> > Any help much appreciated. Thanks!
>> > Tim
>> >
>> > --
>> >
>> > Timothy W. Hilton
>> > Assistant Project Scientist
>> > Sierra Nevada Research Institute
>> > University of California, Merced
>> > thilton at ucmerced.edu
>> >
>> > ______________________________________________
>> > R-help at 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.
Timothy W. Hilton
2015-Jan-27 22:53 UTC
[R] panel.xyplot and panel.loess using two different groupings
Thanks again, Bert, for taking the time to respond to my questions. It's doing exactly what I want now. I'm fairly new with lattice plots but they do seem like a big step forward. I'll look for Deepayan's book; thanks for the tip. -Tim On Tue, Jan 2015, 27 at 02:11:33PM -0800, Bert Gunter wrote:> 1. The trellis.par.get$superpose.line list controls the loess line > appearance, I believe (check this!) > > 2. To control the overall loess curve in the panel, call it without > the "..." arguments, e.g > > panel.loess(x,y, col.line="darkblue") > > You may have to modify argument lists appropriately if you want to > control the loess smoothing parameters in the xyplot call. The problem > is to avoid replicating parameter names that are passed in the "..." > argument with ones that you explicitly call (e.g. col.line above). > This can get a bit tricky.* If you're going to use lattice regularly > (which I recommend -- or ggplot; both are much more powerful and > flexible interfaces than the original base plotting capabilities, > IMHO), I would suggest getting your hands on Deepayan's book in which > these niceties are more fully explained. > > *Also check out the latticeExtra package, as it provides a ggplot-like > syntax ("+") and facilities to handle duplicated parameters in > situations like this. >