[R] plotting the lognormal density curve
Bill.Venables at csiro.au
Wed Apr 9 09:46:38 CEST 2003
OK. You need to start with a "true" histogram, not one of these bastardised
frequency diagrams that hist() by itself produces:
x <- rlnorm(1000, 1, 1) # for example
r <- range(x)
d <- dlnorm(r:r, meanlog = mean(log(x)), sdlog = sd(log(x)))
hist(x, prob = TRUE, ylim = range(d))
lines(r:r, d, col="red")
You will most likely get a better result if you evaluate your density at
(exponentials of) many equally spaced points in the range of log(x).
You will also get a much better histogram using
truehist(x, ylim = range(d))
where truehist() comes from the MASS library (thanks to BDR).
From: Garrett Gman [mailto:grolemun at fas.harvard.edu]
Sent: Wednesday, April 09, 2003 5:25 PM
To: r-help at stat.math.ethz.ch
Subject: [R] plotting the lognormal density curve
I am trying to plot a lognormal density curve on top of an existing
histogram. Can anybody suggest a simple way to do this? Even if someone
could just explain how to plot a regular normal density curve on top of an
existing histogram, it would be a big help.
Also, is there some way to search through the R-help archives other than
Thank you so much. Your help and time is greatly appreciated.
R-help at stat.math.ethz.ch mailing list
More information about the R-help