首页 > 解决方案 > 最新的 gganimate:如何在后台有一个固定的情节?

问题描述

https://github.com/thomasp85提供的最新版本的 gganimate 中,我想选择情节的哪些部分可以在整个动画中保持静态,哪些部分将被动画化。在之前版本的 gganimate 中,您可以在 ggplot 的aes中指定框架。因此,您可以创建一个静态的基本图并在其上绘制动画图。在最新版本中如何实现类似?

标签: rgganimate

解决方案


这已经gganimate在 GitHub 上的一个问题中得到解决:https ://github.com/thomasp85/gganimate/issues/94

基本上,您可以使用与最初传递给的数据框不同的数据框来指定应为静态的层ggplot。我提到的 GitHub 票证中的示例是

library(gganimate)
#> Loading required package: ggplot2
ggplot(dat = data.frame(x=1:10,y=1:10), aes(x=x,y=y)) +
  geom_point() +
  geom_line(data = data.frame(x2 = 1:10, y = 1:10),
            aes(x = x2, y = y, group = 1)) +
  transition_time(x)
animate(last_plot(), nframes = 50)

在这里,线保持静止,而点在移动。


推荐阅读