Re: [R] scaling y-axis to relative frequency in multiple histogram (multhist)

From: Ben Bolker <>
Date: Thu 30 Nov 2006 - 16:09:32 GMT

ahimsa campos-arceiz wrote:
> Dear Ben,
> thank you very much for your prompt reply.
> but I'm afraid I'm missing something: when I apply your function
> pmulthist I
> obtain exactly the same results as with multhist (with the y axis
> representing frequencies rather than a probability).
> I was checking but couldn't find the problem (*"allhist" is clearly set to
> be freq=False*)
> I would appreciate a lot if you can point out what I'm missing.
> Ahimsa

  Sorry, I wasn't thinking. The freq=FALSE/prob=TRUE switches in hist() only affect the plotting of the data, not the calculations. In the second line of the function below I've replaced $counts with $density, which does the trick. I could/should add this to the function in the packages ...

pmulthist <-
function (x, breaks = "Sturges", ...)
  allhist <- hist(unlist(x), breaks = breaks, plot = FALSE)   combhist <- t(sapply(x, function(z) hist(z, breaks = allhist$breaks,

      plot = FALSE)$density))
  barplot(combhist, beside = TRUE, names = signif(allhist$mids,

      2), ...)

    Ben mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code.
Received on Fri Dec 01 03:19:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 30 Nov 2006 - 16:30:22 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.