Code combines the most difficult ggplot2
/dplyr
concepts:
- counting the different values of
n_correct
using n()
instead of sum()
- dividing by the number of simulations
10000
- using
geom_bar()
when we have an explicity y
aesthetic prop_correct
, so we set stat="identity"
simulation <- simulation %>%
group_by(n_correct) %>%
summarise(prop_correct = n()/10000)
ggplot(simulation, aes(x=n_correct, y=prop_correct)) +
geom_bar(stat="identity") +
labs(x="Number of Guesses Correct", y="Proportion") +
geom_vline(xintercept=8, col="red", size=2)