I would like to create an animated bar plot in R which displays the scored goals by each player and gameday.
Below I created fictional data:
df <- data.frame(player = c("Aguero", "Salah", "Aubameyang", "Kane", "Aguero", "Salah", "Aubameyang", "Kane", "Aguero", "Salah", "Aubameyang", "Kane"),
team = c("ManCity", "Liverpool", "Arsenal", "Tottenham", "ManCity", "Liverpool", "Arsenal", "Tottenham", "ManCity", "Liverpool", "Arsenal", "Tottenham"),
gameday = c(1,1,1,1,2,2,2,2,3,3,3,3),
goals = c(0,1,2,0,1,1,3,1,2,1,3,2),
stringsAsFactors = F)
Based on the data I would like to create the animated bar plot. The bar plot should be animated by each game day and display the best scorer above in the plot.
Below I created a created a simple visualization of my idea.
ggplot(data=df, aes(x=reorder(Player, Goals), y=Goals, fill=Team)) +
geom_bar(stat="identity") +
theme(legend.position = "none", axis.text.y=element_blank(),
axis.title.y=element_blank()) +
geom_text(aes(label=Player), vjust=1, hjust=-0.1, color="white", size=3.5) +
coord_flip()
The bar plot is inspired by such a video: https://www.youtube.com/watch?v=U8CpdQnWH7Y
Is there a possibility to create an animated bar plot for that?
Thank you very much for your help!