ahimsa campos-arceiz
2006-Nov-30 11:37 UTC
[R] scaling y-axis to relative frequency in multiple histogram (multhist)
Hi, I'm plotting a multiple histogram using the function multhist {package plotrix}, something like: library(plotrix) mh <- list(rnorm(200, mean=200, sd=50), rnorm(200, mean=250, sd=50)) multhist(mh) In this graph y-axis represents the frequency of observations.... but I would like it to be scaled into relative frequencies, does anybody know how to do this with multhist or similar function? thanks a lot, Ahimsa -- ahimsa campos-arceiz www.camposarceiz.com [[alternative HTML version deleted]]
Ben Bolker
2006-Nov-30 12:40 UTC
[R] scaling y-axis to relative frequency in multiple histogram (multhist)
ahimsa campos-arceiz <ahimsa <at> camposarceiz.com> writes:> > Hi, > > I'm plotting a multiple histogram using the function multhist {package > plotrix}, something like: > > library(plotrix) > mh <- list(rnorm(200, mean=200, sd=50), rnorm(200, mean=250, sd=50)) > multhist(mh) > > In this graph y-axis represents the frequency of observations.... but I > would like it to be scaled into relative frequencies, > > does anybody know how to do this with multhist or similar function? > > thanks a lot, > > Ahimsa >In its current form, multhist doesn't allow the freq=FALSE or prob=TRUE arguments to be passed to hist() (the ... argument passes optional arguments to barplot, not hist). You could hack it as follows: pmulthist <- function (x, breaks = "Sturges", ...) { allhist <- hist(unlist(x), breaks = breaks, plot = FALSE, freq=FALSE) combhist <- t(sapply(x, function(z) hist(z, breaks = allhist$breaks, plot = FALSE)$counts)) barplot(combhist, beside = TRUE, names = signif(allhist$mids, 2), ...) }