[R] Lattice: problem using panel.superpose and panel.groups

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Aug 19 01:20:37 CEST 2008


On Sun, Aug 17, 2008 at 2:36 AM, Dieter Menne
<dieter.menne at menne-biomed.de> wrote:
> Michael Braun <braunm <at> MIT.EDU> writes:
>
>>
>> Dieter:
>>
>> Thank you for your response.  As you requested, I created a self-
>> running example, pasted below.  It may be a little wordier than I
>> would like, but it runs.
>
> .. Details removed
>>
>> panel.ppc.plot <- function(...,group.number) {
>>
>>    if (group.number==1) {
>>      panel.bwplot(...)
>>    } else {
>>
>>      panel.lines(...)
>>    }
>> }
>
> Trellis graphics are a bit like hash functions: you can be close to the
> target, but get a far-off result. I admit that I do not know why
> panel.lines does not work in the above example, but
>
> panel.polygon(...)
>
> works in your special case of ordered data. More generally, I would suggest
> to use
>
> panel.xyplot(x,y,type="l")
>
> or, if you want the ... notation,
>
> panel.xyplot(...)
>
> but then you have to set type="l" in your bwplot calling function.

Yes, in fact the simplest change that works is to do just that:

obj <- bwplot(as.numeric(value) ~ as.factor(count) | dataset + model,
             data = all.data,
             type = "l",  ## added
             panel = panel.superpose,
             groups=group,
             panel.groups = panel.ppc.plot
             )

The problem is that 'panel.superpose' has type="p" as the default, and
so panel.lines ends up being called as

panel.lines(..., type = "p", col = NA)

The 'col = NA' part is also problematic (otherwise at least some
points would have shown up); it works in the case of

panel.lines(..., type = "l", col = NA)

because of a workaround deep in the code for panel.lines. Generally
speaking, as Dieter said, it is safer to use panel.xyplot etc. (and
not lower-level functions like panel.lines) when depending on argument
passing via the ... argument.

-Deepayan



More information about the R-help mailing list