set.seed(42)
n = 1000
x = sample(1:6, n, replace = TRUE)
y = cumsum(x) / seq_along(x) # seq(1, 1000, 1)
df = tibble(x = 1:n, y = y)
ggplot(df, aes(x = x, y = y)) +
geom_line() +
geom_hline(yintercept = 3.5, linetype = "dashed") +
ylim(0, 6) +
theme_minimal() +
labs(title = "Expected Value of a Die Roll", x = "Number of Rolls", y = "Expected Value")