Re: [R] Conditional density plot in lattice

2010-01-28 Thread Deepayan Sarkar
On Fri, Jan 22, 2010 at 2:08 AM, Dieter Menne
 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

__
R-help@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.


Re: [R] Conditional density plot in lattice

2010-01-22 Thread Dieter Menne


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?

Dieter


-- 
View this message in context: 
http://n4.nabble.com/Re-R-Conditional-density-plot-in-lattice-tp1050017p1099911.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Conditional density plot in lattice

2010-01-21 Thread Jim Lemon

On 01/22/2010 04:05 AM, Dieter Menne wrote:

Dear group,

I want to create a plot similar to cdplot or cd_plot I vcd :

http://addictedtor.free.fr/graphiques/graphcode.php?graph=120

with lattice and support for multiple panels. Densities should not be
computed, these are stored in a data frame as in the example. My current
workaround with barchart and ugly jags is given.



Hi Dieter,
I know this is cheating, but what about:

library(plotrix)
stackpoly(cbind(df3$y,df1$y,rep(1,101)),
 col=c("#cc","#cc","#ffccff"),
 xlab="Age",ylab="Proportion",
 main="The folly of youth, the tragedy of age")
legend(20,0.8,c("Young","Old"),
 fill=c("#cc","#cc"),bg="white")

Jim

__
R-help@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.


Re: [R] Conditional density plot in lattice

2010-01-21 Thread Deepayan Sarkar
On Thu, Jan 21, 2010 at 9:05 AM, Dieter Menne
 wrote:
> Dear group,
>
> I want to create a plot similar to cdplot or cd_plot I vcd :
>
> http://addictedtor.free.fr/graphiques/graphcode.php?graph=120
>
> with lattice and support for multiple panels. Densities should not be
> computed, these are stored in a data frame as in the example. My current
> workaround with barchart and ugly jags is given.
>
> Any better solution?
>
> Dieter
>
> library(lattice)
> n = 100
> df1 = data.frame(x=0:n,y=((0:n)/n)^2,group="a",age="young")
> df2 = data.frame(x=0:n,y=1-df1$y,group="b",age="young")
> df3 = data.frame(x=0:n,y=((0:n)/n)^3,group="a",age="old")
> df4 = data.frame(x=0:n,y=1-df3$y,group="b",age="old")
> df = rbind(df1,df2,df3,df4)
>
> barchart(y~x|age,groups=group,
> data=df,horizontal=FALSE,stack=TRUE,box.width=1,
>   lwd=0,lty=0, ylim=c(0,1),scales=list(x=list(at=seq(0,n,n/10)) ))

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)
   })

-Deepayan

__
R-help@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] Conditional density plot in lattice

2010-01-21 Thread Dieter Menne
Dear group,

I want to create a plot similar to cdplot or cd_plot I vcd :

http://addictedtor.free.fr/graphiques/graphcode.php?graph=120 

with lattice and support for multiple panels. Densities should not be
computed, these are stored in a data frame as in the example. My current
workaround with barchart and ugly jags is given.

Any better solution?

Dieter

library(lattice)
n = 100
df1 = data.frame(x=0:n,y=((0:n)/n)^2,group="a",age="young")
df2 = data.frame(x=0:n,y=1-df1$y,group="b",age="young")
df3 = data.frame(x=0:n,y=((0:n)/n)^3,group="a",age="old")
df4 = data.frame(x=0:n,y=1-df3$y,group="b",age="old")
df = rbind(df1,df2,df3,df4)

barchart(y~x|age,groups=group,
data=df,horizontal=FALSE,stack=TRUE,box.width=1,
   lwd=0,lty=0, ylim=c(0,1),scales=list(x=list(at=seq(0,n,n/10)) ))

__
R-help@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.