I would like to plot a normal curve over top of some data that has been plotted in a histogram format. I thought this would be relatively straightforward. So far I have:
x = rnorm(2000, mean=-5, sd=4)
a_hist = ggplot() +
geom_histogram(aes(x), fill='darkred') +
stat_function(fun=dnorm, args(list(mean=-5, 4)))
This gets me everything except the normal curve. I'm guessing it's because of the axes but when I tried to mess around with the mean/SD/counts it still didn't show. I also thought it might be because of the aes mappings. But ggplot wouldn't allow me to put the data into the base ggplot
call since its a vector and not a dataframe. Trying to coerce it into a data frame and passing it in as such gave me other errors. I explored the stat_function()
parameter position
but couldn't find any documentation on how to use it other than 'it takes a string'.