hist.group <- function (x, y) { stopifnot(is.numeric(x), is.factor(y)) histinfo<- tapply(x, y, hist, plot=FALSE) breaks <- NULL mids.n <- NULL for (i in 1:dim(histinfo)) { breaks <- c(breaks, histinfo[[i]][["breaks"]]) mids.n <- c(mids.n, length(histinfo[[i]][["mids"]])) } histinfo<- tapply(x, y, hist, breaks=seq(min(breaks), max(breaks), length=max(mids.n)+1), plot=FALSE) counts <- NULL breaks <- NULL mids.n <- NULL for (i in 1:dim(histinfo)) { counts <- c(counts, histinfo[[i]][["counts"]]) breaks <- c(breaks, histinfo[[i]][["breaks"]]) mids.n <- c(mids.n, length(histinfo[[i]][["mids"]])) } histinfo<- tapply(x, y, hist, breaks=seq(min(breaks), max(breaks), length=max(mids.n)+1), xlim=range(breaks), ylim=range(counts)) } par(mfrow=c(3,2)) #hist.group(InsectSprays$count, InsectSprays$spray)