[R] Lattice and horizontally stacked density plots

Manish Nag nagm01 at gmail.com
Wed Feb 22 23:01:13 CET 2012


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)


More information about the R-help mailing list