
Simulation

Below you can find the code in R that generated the above animation
library(ggplot2)
library(gganimate)
library(gifski)
# Number of tosses
number_of_tosses <- 1000
outcome <- sample(c(0,1), size=number_of_tosses, replace = TRUE)
proportion_of_heads_at_each_time <- cumsum(outcome)/1:number_of_tosses
df <- data.frame(proportion_of_heads_at_each_time)
g <- ggplot( df, aes(x=1:number_of_tosses,y=proportion_of_heads_at_each_time)) +
labs(x="Number of tosses", y= "Proportion of heads") +
ylim(c(0.1,0.8))+
geom_hline(yintercept = 0.5, show.legend = TRUE, linetype = "dashed")+
geom_line() +
geom_point() +
geom_text(aes(label=round(fracs,digits = 3)),hjust=-0.2, vjust=-0.2) +
transition_reveal(1:steps) +
ease_aes('sine-in-out') +
theme_light()+
theme(panel.border = element_blank())
animate(g, renderer = gifski_renderer(), duration = 15, width=800, height=600)
anim_save(DIRECTORY_NAME_TO_SAVE_THE_FILE)