Hi
I would like to superimpose group-specific densityplots on top of an overall
histogram using panel.histogram and panel.densityplot. Furthermore, I would
like to automatically adjust the range of the y-axis to take into account
the ranges of both histogram and densityplot. This last part is where I have
a problem. I believe using the prepanel argument of histogram is typically
the way to go, but I did not have very much success with my attempts. Is
this the way to go, or should I calculate the range outside the histogram
call using some stat function (density?) on each group and use it as a ylim
argument?
Any advise would be greatly appreciated.
Thank you
Sebastien
require(lattice)
set.seed(12345)
foo1 <- data.frame(x=rnorm(100,0,0.1),grp=1)
foo2 <- data.frame(x=rnorm(100,2,1),grp=2)
foo <- rbind(foo1,foo2)
#
# Some code to calculate ylim...
#
histogram(~x,data=foo,groups=grp,
#prepanel=function(x,type,groups,...){???},
panel=function(x,type,groups,...){
panel.histogram(x,col='transparent',...)
panel.densityplot(x,groups=groups,...)
},
#ylim=ylim,
type='density')
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.