[R] Conditional density plot in lattice
Dieter Menne
dieter.menne at menne-biomed.de
Thu Jan 21 18:05:50 CET 2010
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)) ))
More information about the R-help
mailing list