gganimate returns .png files, but no animated object

浪尽此生 提交于 2021-02-07 14:41:14

问题


I am trying to create an animation to show students how to represent data with animations. Running the below code

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)

I was expecting an animation on a preview window and the creation of a gif image.

Conversely, what I am getting is 100 .png files in the working directory, but nothing else. The pictures are correct and are the frames of the animation, they are just not put together by the function. In particular I get 100 elements of which I show the first elements here: This list

  [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"...

And

    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

and

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

And finally this

 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

Am I doing something wrong?


回答1:


make sure you have one of the packages required to combine images into videos. I'd advice you to use gifski:

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

and restart R



来源:https://stackoverflow.com/questions/58991580/gganimate-returns-png-files-but-no-animated-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!