[R] Set panel background color in a multi-group trellis plot

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Nov 30 21:40:15 CET 2007


On 11/30/07, crmontes at ncsu.edu <crmontes at ncsu.edu> wrote:
> Thanks,
>
> I'll finaly figure it out.  It was not very intuitive though, even looking
> at the help file.  The final code, for whom it might interest is:
>
>  xyplot(Volume ~ Age|Farm,
>                  groups       = Treatment,
>                  data         = my_data,
>                  panel        = panel.superpose,
>                  panel.groups =  function(x,y, group.number, ...)
>                    {
>                      if (group.number == 1)panel.fill(col = "white")
>                      panel.grid(col = "gray",lty = 2)
>                      panel.xyplot(x,y,...)
>                   }

I would have done it slightly differently:

xyplot(Volume ~ Age|Farm,
                groups       = Treatment,
                data         = my_data,
                panel        = function(...) {
                    panel.fill(col = "white")
                    panel.grid(col = "gray",lty = 2)
                    panel.superpose(...)
                },
                panel.groups =  function(...)
                  {
                    panel.xyplot(...)
                 }

and as panel.groups is not doing anything new any more (and
panel.xyplot does what panel.superpose does anyway if you are using
the default panel.groups), simplify this further to

xyplot(Volume ~ Age|Farm,
       groups       = Treatment,
       data         = my_data,
       panel        = function(...) {
           panel.fill(col = "white")
           panel.grid(col = "gray",lty = 2)
           panel.xyplot(...)
       })

-Deepayan

>
> Cristián Montes
> NCState University
>
>
> > Read ?panel.superpose carefully and pay attention to the comments about
> > the
> > group.number argument passed to panel.groups. You can test the value of
> > this
> > argument and adjust the plot accordingly.
> >
> >
> >
> > Bert Gunter
> > Genentech Nonclinical Statistics
> > 7-7374
> >
> > -----Original Message-----
> > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> > On
> > Behalf Of crmontes at ncsu.edu
> > Sent: Friday, November 30, 2007 8:50 AM
> > To: r-help at r-project.org
> > Subject: [R] Set panel background color in a multi-group trellis plot
> >
> > Hi everyone,
> >
> > I am trying to change some of the default colors in a
> > multipanel-multigroup lattice graphic, but when I change the panel color
> > to white, the only group that is plotted is the last one, as panel.fill
> > overwrites all the previous ones.  Is there any way to set the panel
> > background color for the first panel to a color and keep the rest
> > transparent?
> >
> > My code looks like this:
> >
> > #first set defaults for getting more distinct symbols
> > superp.symbol <- trellis.par.get("superpose.symbol")
> > superp.symbol$pch = 15:21
> > superp.symbol$cex = 1.5
> > trellis.par.set("superpose.symbol", superp.symbol)
> >
> > #set the default for the colors in the symbols
> > superp.lines <- trellis.par.get("superpose.line")
> > superp.lines$lty <- 1:6
> > superp.lines$lwd <- 1.5
> > trellis.par.set("superpose.line", superp.lines)
> >
> > #set the device color to lightblue
> > trellis.par.set("background", list(col = "lightblue"))
> >
> >
> > xyplot(Volume ~ Age|Farm,
> >                 groups       = Treatment,
> >                 data         = my_data,
> >                 panel        = panel.superpose,
> >                 panel.groups =  function(x,y, ...)
> >                   {
> >                     panel.fill(col = "white")
> >                     panel.grid(col = "gray",lty = 2)
> >                     panel.xyplot(x,y,...)
> >                  }
> >
>
> ______________________________________________
> 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.
>


More information about the R-help mailing list