【问题标题】:How to stop gganimate after one loop of animation在一个动画之后如何停止生理
【发布时间】:2021-11-13 09:57:30
【问题描述】:

是否可以在动画循环一圈后停止?

动画应该执行到去年 2021 年,然后停止显示所有条形图!

这是带有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)

【问题讨论】:

    标签: r ggplot2 gganimate


    【解决方案1】:

    您可以在 gifski 渲染器中设置此选项。

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

    【讨论】:

    • 非常好的 JRR。此外,我添加了 `wrap = FALSE` 参数以在最后停止。干得好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多