3

Is it possible to stop after one loop of animation?

Animation should be performed until last year 2021 then stop showing all bars!

Here is an example animation of bars with gganimate:

library(tidyverse)
library(gganimate)

year <- (2000:2021)
something <- mtcars$mpg[1:22]

df <- tibble(year,something)

p <- ggplot(df, aes(year, something))+
    geom_col() +
    geom_text(aes(label=something), vjust=-0.3, size=4)+
    transition_states(year, transition_length = 5, state_length = 10) + shadow_mark() +
    enter_grow() + 
    exit_fade(alpha = 1)+
    labs(title = 'Year: {closest_state}',  
         subtitle  =  "Blabla",
         caption  = "bla")

animate(p, fps=8)

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66

1 Answers1

6

You can set this option in the gifski renderer.

animate(p, fps=8, renderer = gifski_renderer(loop = FALSE))
JRR
  • 136
  • 4
  • 1
    Very good JRR. In addition I added ` wrap = FALSE` argument to stop really at the end. Well done! – TarJae Sep 19 '21 at 11:01