gganimate returns .png 文件,但没有动画对象

gganimate returns .png files, but no animated object

我正在尝试创建一个动画来向学生展示如何用动画表示数据。 运行 下面的代码

library(ggplot)
library(gganimate)
library(carData)        
anim <- ggplot(mtcars, aes(mpg, disp)) +
          transition_states(gear, transition_length = 2, state_length = 1) +
          enter_fade() +
          exit_fade()

    animate(anim)

我期待预览动画 window 和 gif 图像的创建。

相反,我得到的是工作目录中的 100 个 .png 文件,除此之外什么都没有。图片是正确的,是动画的帧,只是函数没有把它们放在一起。 特别是我得到了 100 个元素,我在这里展示了第一个元素: 此列表

  [1] "./gganim_plot0001.png" "./gganim_plot0002.png" "./gganim_plot0003.png" 
  [4] "./gganim_plot0004.png" "./gganim_plot0005.png" "./gganim_plot0006.png"
  [7] "./gganim_plot0007.png" "./gganim_plot0008.png" "./gganim_plot0009.png"
 [10] "./gganim_plot0010.png" "./gganim_plot0011.png" "./gganim_plot0012.png"...

    attr(,"frame_vars")
    frame nframes progress transitioning previous_state closest_state
1       1     100     0.01         FALSE              3             3
2       2     100     0.02         FALSE              3             3
3       3     100     0.03         FALSE              3             3

next_state
1            3
2            3
3            3
4            3
5            3
6            3
7            3
8            3
9            3
10           3
11           3
12           3

最后是这个

 frame_source
1   C:\Users\rosar\AppData\Local\Temp\RtmpIR4dH3\3b84232b4eef/gganim_plot0001.png
2   C:\Users\rosar\AppData\Local\Temp\RtmpIR4dH3\3b84232b4eef/gganim_plot0002.png
3   C:\Users\rosar\AppData\Local\Temp\RtmpIR4dH3\3b84232b4eef/gganim_plot0003.png

我是不是做错了什么?

确保您拥有将图像组合成视频所需的软件包之一。我建议你使用 gifski:

install.packages('gifski')
install.packages('png')

并重启 R