Skip to content
Prev 386940 / 398502 Next

Plot histogram and lognormal fit on the same time

Hello,

A solution based on Marc's first one, maybe easier? (It doesn't rely on 
multiplying the dlnorm values by 400 since it plots the histogram with 
freq = FALSE.)


set.seed(2020)
data <- rlnorm(100, meanlog = 1, sdlog = 1)

library(MASS)

f <- fitdistr(data, "lognormal")
f$estimate

p <- pretty(range(data))
x <- seq(from = min(p), to = max(p), by = 0.1)

hist(data, freq = FALSE)
lines(x, y = dlnorm(x,
                     meanlog = f$estimate["meanlog"],
                     sdlog = f$estimate["sdlog"])
)


Hope this helps,

Rui Barradas


?s 13:12 de 21/01/21, Marc Girondot via R-help escreveu: