5

I'd like to create a transition_reveal animation using gganimate whereby the title changes along the currently revealed iteration. So, the title at the start would be "Date: 2019-01-01" and then gradually adapt alongside the animation and finish by showing "Date: 2019-01-20".

a <- seq(1,20,1)
b <- seq(1,40,2)
c <- seq(as.Date("2019-01-01"), as.Date("2019-01-20"), by="days")
db <- cbind(a,b,c) %>% as.data.frame()

p <- ggplot(db, aes(x = a, y = b)) +
  geom_path() +
  labs(title = "Date: {frame_time}") +
  transition_reveal(c)

animate(p, renderer = gifski_renderer(loop = FALSE), nframes = 90, fps = 30, height = 600, width = 1100, start_pause = 0)

Currently, I get the following error:

50: object 'fame_time' not found
wind_2801
  • 131
  • 10
  • 10
    Read `?transition_reveal` - this function makes the variable `frame_along` available. – markus Jan 31 '19 at 09:44
  • 6
    thank you very much markus! with your hint and a bit of thinkering, the code does what it should by switching to the following labs-line -> labs(title ="Date: {as.Date.numeric(frame_along, origin = '1970-01-01')}") + – wind_2801 Jan 31 '19 at 10:25
  • @wind_2801 if you feel like it, please post this as an answer just for posterity. I found the comments by both to be very helpful but as always an answer is preferable! – User2321 Dec 11 '21 at 05:41

0 Answers0