[R] Plot histogram and lognormal fit on the same time
Marc Girondot
m@rc_grt @end|ng |rom y@hoo@|r
Thu Jan 21 14:12:16 CET 2021
Two solutions not exactly equivalent ;
data <- rlnorm(100, meanlog = 1, sdlog = 1)
histdata <- hist(data, ylim=c(0, 100))
library(MASS)
f <- fitdistr(data, "lognormal")
f$estimate
lines(x=seq(from=0, to=50, by=0.1),
� y=dlnorm(x=seq(from=0, to=50, by=0.1), meanlog =
f$estimate["meanlog"], sdlog = f$estimate["sdlog"])*400
)
library(HelpersMG)
m <- modeled.hist(breaks=histdata$breaks, FUN=plnorm,
����������������������������� meanlog = f$estimate["meanlog"], sdlog =
f$estimate["sdlog"], sum = 100)
points(m$x, m$y, pch=19, col="red")
Marc Girondot
Le 21/01/2021 � 12:54, Eric Leroy a �crit�:
> Hi,
>
> I would like to plot the histogram of data and fit it with a lognormal
> distribution.
>
> The ideal, would be to superimpose the fit on the histogram and write
> the results of the fit on the figure.
>
> Right now, I was able to plot the histogram and fit the density with a
> lognormal, but I can't combine all together.
>
> Here is the code I wrote :
>
> histdata <- hist(dataframe$data)
>
> library(MASS)
>
> fitdistr(histdata$density, "lognormal")
>
> Can you help me ?
>
> Best regards,
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list