I try to superimpose a function via stat_function()
in ggplot
but can't figure out my mistake. this example produces a nice looking plot:
data <- data.frame(x=rt(10000, df=7))
ggplot(data=data, aes(x=x)) + geom_histogram(aes(y = ..density..)) +
stat_function(fun =dnorm, size=1, color='gray', args=list()) +
opts(title="Histogram of interest rate changes") + theme_bw()
but when i try to superimpose a log-normal density this doesn't work as expected (or should I say as expected this doesn't work ;):
data <- data.frame(x=rf(10000, df1=7, df2=120))
ggplot(data=data, aes(x=x)) + geom_histogram(aes(y = ..density..)) +
stat_function(fun =dnorm, size=1, color='gray', args=list(log=TRUE)) +
opts(title="Histogram of interest rate changes") + theme_bw()
so here's my hopefully simple question: what am I doing wrong here? I guess this is a really simple problem I just don't see the answer - sorry.
Use dlnorm
, the density function of the log-normal distribution:
ggplot(data=data, aes(x=x)) + geom_histogram(aes(y = ..density..)) +
stat_function(fun = dlnorm, size=1, color='gray') +
opts(title="Histogram of interest rate changes") + theme_bw()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With