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

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri, 30 Nov 2007 12:40:15 -0800

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.
>



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. Received on Fri 30 Nov 2007 - 20:43:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 30 Nov 2007 - 21:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.