[R] Conditional density plot in lattice

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Jan 28 16:29:49 CET 2010


On Fri, Jan 22, 2010 at 2:08 AM, Dieter Menne
<dieter.menne at menne-biomed.de> wrote:
>
>
> Deepayan Sarkar wrote:
>>
>> With a restructuring of the data:
>>
>> df1 = data.frame(x=0:n, y1=((0:n)/n)^2, y2=1-((0:n)/n)^2, age="young")
>> df2 = data.frame(x=0:n, y1=((0:n)/n)^3, y2=1-((0:n)/n)^3, age="old")
>> df = rbind(df1, df2)
>>
>> xyplot((y1+y2) + y1 ~ x | age, data=df, type = "l")
>>
>> xyplot((y1+y2) + y1 ~ x | age, data=df, type = "l",
>>        scales = list(axs = "i"),
>>        panel = panel.superpose,
>>        panel.groups = function(x, y, fill, ...) {
>>            panel.polygon(c(min(x), x, max(x)), c(0, y, 0), fill = fill)
>>        })
>>
>>
>
> Thanks, Deepayan. I noted, that the color of the bands is determined by
> "superpose.symbol". Is that by design or typo?

By design, in the sense that the default 'fill' for panel.superpose is
taken from superpose.symbol$fill, which makes sense because the
default is to plot symbols.

You could supply a top-level vector 'fill' instead (which could be
trellis.par.get("superpose.poygon")$fill).

-Deepayan



More information about the R-help mailing list