I'm trying to learn how to get a pretty animate graphic using R and gganimate, and I encounter some issue. When I try to animate my graphics, R seems to edit few PNG files, but then fail to render them. Here is an example of the code I use (tidyverse, gganimate, and gifski were loaded first):
p <- ggplot(iris, aes(Sepal.Length, Petal.Length)) + geom_point()
p + transition_states(Species)
R run the first line without issue. When it comes to the second line, console prints "rendering ----> etc.", with a countdown for a few seconds. Once it's over, it prints a lots of lines, which seems to describe the animated object (a list of PNG files, a list of states, etc.). I am guessing that's normal.
Finally, and it seems to me it is the issue, R give me a warning message:
file_renderer failed to copy frames to the destination directory
And of course, I got no animation.
I saw other subjects about this, saying maybe it is a permission issue, but I am not good enough to understand what to do. I reproduced the issue on two machines, one on Ubuntu, the other on Windows.
first, install the gifski
package and type the code below. I have added another line. notice how +transition_states(Species)
is part of the first line to make one p
p <- ggplot(iris, aes(Sepal.Length, Petal.Length)) +
geom_point()+
transition_states(Species)
animate(p, renderer = gifski_renderer())
I really do not get why, but the problem have been solved by itself. On both computers, and both OS, the same code is now working. I didn't change anything, so can't tell what is the reason, and it's very weird because the two machines have nothing in common. Yet, they both couldn't create an animation two days ago, and they both can now.
Conclusion : if anyone have the same issue, maybe just retry a bit later ?
Conclusion 2: maybe I am just stupid, but I could use an explanation to know why then :)
Deleting any previously created images from the directory solved the problem for me. You can do this manually (select those images, then delete them) or using file.remove()
from within R
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With