Skip to content

Density curve over a histogram

6 messages · Achim Zeileis, Uwe Ligges, Vincent Goulet +2 more

#
Dear All

I would like to draw a picture with the density curve of a normal
distribution over a histogram of a set of random numbers extracted
from the same normal distribution. Is that possible?

Thanks in advance,

Paul
#
On Wed, 27 Apr 2005 19:06:07 +0100 Paul Smith wrote:

            
To quote Simon `Yoda' Blomberg: "This is R. There is no if. Only how."
(see fortune("Yoda"))

Try:

R> x <- rnorm(100)
R> hist(x, freq = FALSE)
R> curve(dnorm, col = 2, add = TRUE)

Z
#
Paul Smith wrote:

            
Yes.

If you like to know how, see e.g. ?hist and ?curve.

Uew Ligges
#
Le 27 Avril 2005 14:06, Paul Smith a ??crit??:
Sure. See curve() with add=TRUE. Don't forget to use prob=TRUE when plotting 
your histogram, though.

Vincent
#
On 4/27/05, Achim Zeileis <Achim.Zeileis at wu-wien.ac.at> wrote:
Fantastic! Thanks a lot, Achim.

Paul
#
Paul Smith <phhs80 at gmail.com> writes:
Yes. If you look at the scripts that go with the ISwR package, you'll
find a detailed example in ch01.R (end of 1.3/beginning of 1.4). Or
you could read the book, of course...