[R] Lattice and horizontally stacked density plots
nagm01 at gmail.com
Thu Feb 23 05:28:17 CET 2012
> With lattice alone you can easily get all curves on the same level:
> densityplot(~ val | factor(id2), groups=factor(id1),data=a_df,pch='|')
I just tried the method above. Unfortunately it just makes plots with
different colored lines that overlap one another. Can anyone point me
to an example where people plot their own lines in a panel function?
> But if that doesn't do it for you, you could write your own panel
> function. I don't have time to try it but I'm thinking one of these
> might work
> create new ylim from current.panel.limits()$ylim / number of groups
> dens<- density(x)
> use lines and polygons to draw the curves dens$x,dens$y at each new ylim level.
> 2) grid may come in handy here, splitting each panel into several viewports ?
> 3) use bwplot for "setup" but plot polygons of density (steps 2:3 from option 1)
> Good luck with that.
> On Wed, Feb 22, 2012 at 3:01 PM, Manish Nag <nagm01 at gmail.com> wrote:
>> I am try to make a density plot where plots are stacked like the one
>> found here:
>> I am facing problems, however. Using the code example below, I'd like
>> to generate a separate panel for each val of id2. Within each panel,
>> I'd like to have individual histograms each on separate lines based on
>> the value of id1. Note that the code example works fine if I use
>> "boxplot" instead of "densityplot". Any pointers would be much
>> id1<-sample(c(1:5), 100, replace = TRUE)
>> id2<-rep(c(6:10),100, replace = TRUE)
>> a_df<-data.frame(cbind(id1, id2, val))
>> densityplot(factor(id1) ~ val | factor(id2), data=a_df)
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help