Plotting histograms together can be fine, but it breaks down when you have more than two histograms, or the more they overlap, both of which apply in your case. I would suggest you start by making a plot matrix (so long as you don't have so many groups the plots become unusable).
Likewise, plots with too many, and too different, objects can become difficult to interpret. You want to compare histograms, and you want to compare kernel density plots. Note that a plot matrix has a main diagonal for each group, and then the upper and lower triangles are symmetrical. For a given plot in the upper triangle that compares two groups, there is a corresponding plot in the lower triangle that compares the same two groups. Thus, I would suggest you compare histograms in the upper triangle plots, and kernel density plots in the lower triangle plots.
Because it might still be difficult to compare two overlapping histograms in the subplots, I would suggest you make back to back histograms instead of overlapping histograms.
Putting these suggestions together, you could get something like this:
This was coded using R
. The double histogram code was adapted from here. I suspect the code won't be interpretable to people who aren't already very familiar with R
, but for those who do want to see it, it is displayed below:
data(mtcars)
d = mtcars[,c("qsec","cyl")]
ud = unstack(d)
ud = data.frame(four = c(ud[[1]], rep(NA,3)),
six = c(ud[[2]], rep(NA,7)),
eight = ud[[3]] )
upper = function(x, y){
usr = par("usr"); on.exit(par(usr)); par(usr = c(0, 1, 0, 1), new=TRUE)
hx = hist(x, plot=FALSE)
hy = hist(y, plot=FALSE)
lim = ifelse(max(hy$counts)>max(hx$counts), max(hy$counts), max(hx$counts))
hy$counts = - hy$counts
plot(hy, ylim=c(-lim, lim), col="red", xlim=c(14,23), axes=FALSE, main="")
lines(hx, col="blue")
abline(h=0)
}
diag.hist = function(x, ...){
usr = par("usr"); on.exit(par(usr)); par(usr=c(usr[1:2], 0, 1.5), new=TRUE)
hist(x, freq=FALSE, xlim=c(14,23), ylim=c(0,.8), main="", axes=FALSE)
lines(density(na.omit(x)))
}
lower = function(x, y){
usr = par("usr"); on.exit(par(usr)); par(usr = c(0, 1, 0, 1), new=TRUE)
plot( density(na.omit(x)), xlim=c(14,23),ylim=c(0,.5),main="",axes=FALSE, col="blue")
lines(density(na.omit(y)), col="red")
}
windows()
pairs(ud, upper.panel=upper, diag.panel=diag.hist, lower.panel=lower)