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:
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)