Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gganimate returns .png files, but no animated object

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?

like image 277
Rosario Avatar asked Nov 22 '19 09:11

Rosario


1 Answers

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

like image 58
ThomasP85 Avatar answered Sep 21 '22 17:09

ThomasP85