[R] Use different panel functions with lattice

Balaitous balaitous at mailoo.org
Sat Mar 10 21:47:17 CET 2012


Le samedi 10 mars 2012 à 12:25 -0700, ilai a écrit :
> On Sat, Mar 10, 2012 at 9:33 AM, Balaitous <balaitous at mailoo.org> wrote:
> > Hi,
> >
> > I have a data.frame df with
> > names(df) = c("Var1", "Var2", "Var3", "Var4")
> >
> > and I plot data with
> >
> > xyplot(Var1+Var2~Var3|Var4, data=df)
> >
> > I want to use different panel functions for Var1 and Var2.
> > How can I do ?
> 
> You didn't specify which "different panel functions" you want. Is
> something like this what you're looking for?
> 
>  xyplot(Var1+Var2~Var3|Var4, data=df, panel=panel.superpose,
>  panel.groups=function(x , y , group.number , ...){
>  panel.xyplot(x , y[group.number==1] , ...)
>  panel.lines(x , y[group.number==2] , lwd=2 , col=1)
> })

Var1 and Var2 are 2 two different observed variables (with different scales)
Var3 is the time
Var4 is the point of observation

I have also a Var5 for groups, but I just want groups for the Var1.
I do :

  panel.myrect = function(x, y, font, fontface, ...) {
    panel.rect(xleft=x-.5, xright=x, ybottom=0, ytop=y, fill=TRUE, ...)
  }
  panel.mypanel = function(x, y, ...) {
    panel.superpose(x, y, ...)
  }
  graph = xyplot(RR+temp~heure|date, data=data, groups=name, font="",
    panel=panel.mypanel,
    panel.groups=panel.myrect,
    auto.key=list(columns=3))
  useOuterStrips(graph)

But I don't know how to make the test
  if(Varx)
in the function panel.mypanel, because I need

Var1 -> panel.superpose (It's OK)
Var2 -> panel.lines (I don't want groups for this)

(And I will have others variables with other panel functions to use)

> >
> > Something like :
> >
> > panel.mypanel = function(x, y, ...) {
> >  if (Var1) panel.Var1Panel(x, y, ...)
> >  else panel.Var2Panel(x, y, ...)
> > }
> > xyplot(Var1+Var2~Var3|Var4, data=df, panel=panel.mypanel)
> >
> > (I have search with google, but I found nothing)
> >
> > Thanks
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > 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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: graph.png
Type: image/png
Size: 78340 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120310/602f109c/attachment.png>


More information about the R-help mailing list