I've been looking around online and I can't find a clear answer how to fill different sections under the normal distribution using ggplot and stat_function --> dnorm.
#Parameters
mu = 18.7
sigma = 36.4
n = 168
x = c(mu - 4*sigma/sqrt(n), mu + 4*sigma/sqrt(n))
Here's what I have for the plot
ggplot(data, aes(x)) +
stat_function(fun = dnorm,
args = list(mean = mu, sd = sigma/sqrt(n)),
geom = "area",
fill = "steelblue")
What I want is to fill the first standard deviation one color, the second another color, and so on. I've also noticed that the curve does not appear smooth. Any reason why?
Thanks in advance.
stat_function
has an argumentn
for how many points along the curve to use. It's default is 101. You can use higher values ofn
to make the curve smoother. - Gregor ThomasError: You're passing a function as global data
, because you're suggesting thatdata
is adata.frame
object when to the rest of us, it is theutils::data
function. - r2evans