Code
library(tidyverse)
ggplot(
data = tibble(x = seq(0, 20, 0.01)),
aes(x = x)
) +
stat_function(
fun = dchisq,
args = list(df = 5),
color = "purple", size = 1
) +
# add vertical lines for mean, median and mode
geom_vline(xintercept = 5, color = "red", linetype = "dashed") +
geom_vline(xintercept = 4.35, color = "blue", linetype = "dashed") +
geom_vline(xintercept = 3, color = "seagreen", linetype = "dashed") +
# label the lines
annotate("text", x = 3.6, y = 0.06, label = "Mode", color = "seagreen") +
annotate("text", x = 5.6, y = 0.09, label = "Mean", color = "red") +
annotate("text", x = 5.1, y = 0.03, label = "Median", color = "blue") +
labs(
x = "x",
y = "Density"
) +
theme_bw()