1

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. Thanks

  • Maybe this helps to answer your question: [Animated dot histogram, built observation by observation (using gganimate in R)](https://stackoverflow.com/questions/61446108/animated-dot-histogram-built-observation-by-observation-using-gganimate-in-r) – stefan Oct 16 '22 at 08:17
  • Thanks, I checked that, but I still have a problem, maybe because I am dealing with categorical variables. – user3407369 Oct 16 '22 at 14:24

0 Answers0