library(ggplot2)
p <- ggplot(NULL, aes(c(-4,4))) +
geom_line(stat = "function", fun = dnorm) +
geom_area(stat = "function", fun = dnorm, fill = scales::muted("blue"), xlim=c(-1,1), alpha=1/4) +
geom_area(stat = "function", fun = dnorm, fill = scales::muted("blue"), xlim=c(-2,2), alpha=1/4) +
geom_area(stat = "function", fun = dnorm, fill = scales::muted("blue"), xlim=c(-3,3), alpha=1/4) +
theme_minimal() +
theme(axis.text.x = element_text(size = 12)) +
scale_x_continuous(labels = label_units, breaks = -4:4) +
xlab("Standard Deviations from the Mean") +
ylab("Probability Density") +
geom_segment(aes(x=-1, xend=1, y=dnorm(1), yend=dnorm(1)), linetype="dashed") +
geom_segment(aes(x=-2, xend=2, y=dnorm(2), yend=dnorm(2)), linetype="dashed") +
geom_segment(aes(x=-3, xend=3, y=dnorm(3), yend=dnorm(3)), linetype="dashed") +
annotate("text", x = 0, y = dnorm(1)+0.015, label = "68.3%") + #pnorm(1)-pnorm(-1) %
annotate("text", x = 0, y = dnorm(2)+0.015, label = "95.4%") +
annotate("text", x = 0, y = dnorm(3)+0.015, label = "99.7%")
ggsave("Normal_Distribution.png", p, width = 3.7*1.618, height = 3.7, dpi = 1000)