19

Is it possible to add a pause between gganimate loops? I know we can set the interval between frames with interval, but is there a way to pause on the final frame before looping back to the first frame?

Is the best method to insert multiple copies of the final frame into the data?

willk
  • 3,727
  • 2
  • 27
  • 44

3 Answers3

16

In recent versions of gganimate, the animate() function has an end_pause option. So you can simply do

animate(p, end_pause = 30)

in order to pause for, for example, 30 frames before looping again.

NickCHK
  • 1,093
  • 7
  • 17
10

It's possible by adjusting the render option in animate. Using an example from the README,

p <- ggplot(airquality, aes(Day, Temp)) + 
  geom_line(size = 2, colour = 'steelblue') + 
  transition_states(Month, 4, 1) + 
  shadow_mark(size = 1, colour = 'grey')
animate(p, renderer = gifski_renderer(loop = F))

Note that this prevents the animation from looping, as opposed to adding a pause between loops. To add a pause between loops, this link should help, as suggested in the answer by Alan:

Any way to pause at specific frames/time points with transition_reveal in gganimate?

bmacGTPM
  • 577
  • 3
  • 12
Hao
  • 7,476
  • 1
  • 38
  • 59
0

A working solution has been provided in another post:

Any way to pause at specific frames/time points with transition_reveal in gganimate?

airq_pause <- airq %>%
  mutate(show_time = case_when(Day %in% c(10,20,31) ~ 10,
                               TRUE                 ~ 1)) %>%
  # uncount is a tidyr function which copies each line 'n' times
  uncount(show_time) %>%
  group_by(Month) %>%
  mutate(reveal_time = row_number()) %>%
  ungroup()

Just edit the following line of code:

mutate(show_time = case_when(Day %in% c(10,20,31) ~ 10,
                                 TRUE             ~ 1),

to something along the lines of:

mutate(show_time = case_when(Day %in% max(Day) ~ 10,
                                 TRUE          ~ 1),

and adjust/remove the group_by() call accordingly. It may be necessary to change the ~10 to a higher number to see the pause.

Alan Dursun
  • 655
  • 3
  • 14