[R] panel.xyplot and panel.loess using two different groupings

Bert Gunter gunter.berton at gene.com
Tue Jan 27 20:13:51 CET 2015


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.



More information about the R-help mailing list