多个gganimate图并排显示

6
我想将使用gganimate包制作的动画并排显示,或者至少在同一文档中显示。
要处理的图表:
library(ggplot2)
library(gganimate)

anime_one <- 
  ggplot(mtcars, aes(factor(cyl), mpg)) + 
  geom_boxplot() + 
  # Here comes the gganimate code
  transition_states(
    gear,
    transition_length = 2,
    state_length = 1
  ) +
  enter_fade() + 
  exit_shrink() +
  ease_aes('sine-in-out')

anime_two <- 
  ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(cyl))) + 
  geom_boxplot() + 
  # Here comes the gganimate code
  transition_states(
    gear,
    transition_length = 2,
    state_length = 1
  ) +
  enter_fade() + 
  exit_shrink() +
  ease_aes('sine-in-out')

第一次尝试:
library(patchwork)
anime_one + anime_two  

Error in UseMethod("ggplot_gtable") : 
no applicable method for 'ggplot_gtable' applied to an object of class 
"gganim_built"

第二次尝试:
library(patchwork)
animate(anime_one+anime_two)

这实际上可以渲染而不会出错,但结果只是最后一个“gganim_built”对象(这里是anime_two)的动画。
第三次尝试(有效,但并非我要寻找的解决方案) 我找到的唯一半路解决方案是将所有内容包含在Rmarkdown文档中,然后使用动画调用制作编解码块(每个编解码块只有一个动画调用,否则它无法工作),最后将文档编织到HTML。
```{r}
animate(anime_one)
```

```{r}
animate(anime_two)
```

有人成功地让gganimate对象并排显示吗?
提前感谢。
1个回答

7

看起来gganimate的帮助文档正在重新编写,也许你可以在这里找到关于“动画组合”的解决方案:

https://github.com/thomasp85/gganimate/wiki/Animation-Composition

在标题为“将动画与magick并排放置”的部分中,有一种方法可以实现这样的功能。 希望这可以帮到你。

谢谢。这看起来像是可行的东西 :-) - Steen Harsted

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接