Reputation: 101
I want to add a normal distribution curve in to my density curve to compare between them.
heights %>% filter(sex == "Male") %>% ggplot() +
aes(x = height) +
geom_density(fill = "blue")
What should I do after this?
I want it to be seen like this when it's done:
Upvotes: 0
Views: 649
Reputation: 3876
You could use stat_function
:
heights %>% filter(sex == "Male") %>% ggplot() +
aes(x = height) +
geom_density(fill = "blue") +
stat_function(fun = dnorm, n = 101, size = 1.5, args = list(mean = mean(heights$height[heights$sex == "Male"]), sd = sd(heights$height[heights$sex == "Male"])))
Upvotes: 1