Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop gganimate after one loop of animation

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

like image 529
TarJae Avatar asked Oct 23 '25 19:10

TarJae


1 Answers

You can set this option in the gifski renderer.

animate(p, fps=8, renderer = gifski_renderer(loop = FALSE))
like image 119
JRR Avatar answered Oct 26 '25 08:10

JRR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!