Have annotations appear in gganimate at specified time

I have a time series line chart that has annotations at specific dates that I'd like to appear only when the animation hits that specific date, and stays until the end of the animation. Below is an example - I'd like the line and text that says "End of WWII" appear once the line hits 1945:

test_animation

library(tidyverse)
library(gganimate)
library(babynames)

# Keep only 1 name
don <- babynames %>% 
  dplyr::filter(name %in% c("Adolph")) 

# Plot
don %>%
  ggplot(aes(x = year, y = n, group=name)) +
  geom_line(aes (color = name)) +
  ggtitle("Popularity of American names Over Time") +
  ylab("Number of babies born") + 
  annotate ("text", x = 1945, y = 225, label = "End of WWII") +
  geom_segment(aes(x = 1945, y = 0,
                   xend = 1945, yend = 215),
               size = 0.25
  ) + 
  transition_reveal(year)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.