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 simple browsing? Thank you so much. Your help and time is greatly appreciated.
For the normal distribution N <- 1000 xSamples <- rnorm(N, mean=0, sd=1) hist(xSamples, freq=FALSE) curve(dnorm(x, mean=0, sd=1), add=TRUE) Similar for log normal; dlnorm() & friends. Cheers Henrik Bengtsson> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Garrett Gman > Sent: den 9 april 2003 09:25 > 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 simple browsing? > > Thank you so much. Your help and time is greatly appreciated. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > >
At 03:25 09/04/2003 -0400, vous avez ?crit:>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.There is an example in An Introduction to R: 8.2 Examining the distribution of a set of data>Also, is there some way to search through the R-help archives other than >simple browsing?http://cran.r-project.org/search.html>Thank you so much. Your help and time is greatly appreciated. > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-helpEP
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[1]:r[2], meanlog = mean(log(x)), sdlog = sd(log(x))) hist(x, prob = TRUE, ylim = range(d)) lines(r[1]:r[2], 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). Bill Venables. -----Original Message----- 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 simple browsing? Thank you so much. Your help and time is greatly appreciated. ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help