# [R] Histogram questions

Thomas Vogels tov at ece.cmu.edu
Tue Feb 6 07:32:24 CET 2001

```Thomas Lumley <tlumley at u.washington.edu> writes:

> On Mon, 5 Feb 2001, M. Edward (Ed) Borasky wrote:
>
[snip]
> > 3. What would be even nicer is to have "hist" and "density" *both* scale their
> > outputs as probabilities, so they could be overlaid on a plot together. How
> > difficult is this to do?
>
> They both *do* scale their outputs as probability densities so they *can*
> be overlaid. They couldn't be overlaid if the bar heights added up to 1,
> since then the histogram wouldn't be a density estimate.
>
> Eg
>  data(faithful)
>  hist(faithful\$eruptions,prob=TRUE)
>  lines(density(faithful\$eruptions))

what appears to be working better for me in practice is to take care
of ylim:

> x <- rnorm(100)
> hh <- hist (x, prob=TRUE, plot=FALSE)
> dd <- density (x)
> hist (x, prob=TRUE, ylim=c(0, max(hh\$intensities, dd\$y)))
> lines (dd)

the reason I bring this up is that:

> hist (x, prob=TRUE)

is not the same as:

> plot (hh <- hist (x, prob=TRUE))

as one might naively expect...

Regards,
-tom

--
mailto:tov at ece.cmu.edu (Tom Vogels)   Tel: (412) 268-6638   FAX: -3204
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```

More information about the R-help mailing list