[R] superpose.polygon, panel.polygon and their colors

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Oct 20 17:34:05 CEST 2010


On Wed, Oct 20, 2010 at 7:53 AM, ottorino
<ottorino-luca.pantani at unifi.it> wrote:
> Il giorno mer, 20/10/2010 alle 03.05 -0700, Dennis Murphy ha scritto:
>> Works for me!  Thanks, Dieter!
>
> Hi all.
> Thanks again to you both for the help.
>
> It was a problem due to a lack in updating ubuntu.
> After the upgrade to Lucid I entirely forgot to
> update /etc/apt/sources.list with the new lines.
> For some reason I only commented the old lines with hardy.
>
> After R re-installation and upgrade.packages(), everything is working as
> expected.

For the record, the problem with the old lattice (0.18) was that
panel.superpose() didn't pass on 'col' to panel.groups; it passed on
'col.line' and 'col.symbol' instead. (Actually, it passed on col=NA,
which is even worse). This was OK for the default
panel.groups=panel.xyplot, but obviously a problem in cases like this.
lattice 0.19 fixes this.

One approach that will work both versions is to use a different
parameter that panel.superpose() does pass on.  'fill' seems
appropriate here, e.g.,

 panel.bands <-
    function(x, y, upper, lower,
             subscripts, ..., col, fill)
{
    upper <- upper[subscripts]
    lower <- lower[subscripts]
    panel.polygon(c(x, rev(x)), c(upper, rev(lower)), ..., col = fill)
}

xyplot(est ~ x | cond, group = grp, data = data, type = 'b',
       upper = data$upper,
       lower = data$lower,
       fill = "grey",
       panel = function(x, y, ...){
           panel.superpose(x, y, panel.groups = 'panel.bands', ...)
           panel.xyplot(x, y, ...)
       })

-Deepayan



More information about the R-help mailing list