Home > Software design >  How to stop gganimate after one loop of animation
How to stop gganimate after one loop of animation

Time:09-22

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

CodePudding user response:

You can set this option in the gifski renderer.

animate(p, fps=8, renderer = gifski_renderer(loop = FALSE))
  • Related