I have a data frame of countries and some events in each country. How to animate a dotplot of events for each country through time
df <- data.frame(country = factor(c("Mexico", "USA","France", "USA","France","Mexico", "USA")),
start_date =as.Date(c("2016-01-26", "2016-02-26","2016-03-26","2016-04-26","2016-05-26","2016-04-26","2016-05-26")),
events = factor(c("Protest", "Election","Covid","Protest", "Election","Protest", "Election"))
)
here is my code:
p1 <- ggplot(df, mapping = aes(x=country))+
geom_dotplot()
p1
I have a data frame of countries and some events in each country. How to animate a dotplot of events for each country through time
df <- data.frame(country = factor(c("Mexico", "USA","France", "USA","France","Mexico", "USA")),
start_date =as.Date(c("2016-01-26", "2016-02-26","2016-03-26","2016-04-26","2016-05-26","2016-04-26","2016-05-26")),
events = factor(c("Protest", "Election","Covid","Protest", "Election","Protest", "Election"))
)
here is my code:
p1 <- ggplot(df, mapping = aes(x=country))+
geom_dotplot()
p1
I want to animate it over the time
p_anim <- p1 + transition_time(start_date) +
transition_layers(keep_layers = FALSE) +
transition_reveal(start_date)+
ease_aes("linear") +
enter_fade() +
exit_fade()
animate(p_anim)
It only puts the dots on the x-axis and doesn't stack them. What is the solution? Thanks