1、安裝
install.packages("gganimate")
library(gganimate)
提示安裝gifski和av包,否則后臺無法渲染亮垫。No renderer backend detected. gganimate will default to writing frames to separate files.
2、警告和錯誤信息提示
install.packages(c("gifski", "av"))
p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) +geom_point()
anim <- p + transition_states(Species, transition_length = 2, state_length = 1)
animate(anim)
仍無法渲染,警告信息:file_renderer failed to copy frames to the destination directory.
> anim_save("1.gif", animation=anim)
Error: The animation object does not specify a save_animation method
In addition: Warning message:
file_renderer failed to copy frames to the destination directory
也無法正常保存為gif琅攘。
3、解決辦法
> animate(anim, renderer = gifski_renderer())
Inserting image 100 at 9.90s (100%)...
Encoding to gif... done!
> pa <- animate(anim, render = gifski_renderer()
> print(pa)
> anim_save("pa.gif", animation=pa)
- animate()正常顯示松邪,必須調(diào)用render=gifski_renderer()
- anim_save()正常保存坞琴,必須先返回plot對象,然后print(),最后保存為gif逗抑。
4剧辐、一種更簡單的方法
安裝ImageMagick, 讓animate()自行調(diào)用ImageMagick來顯示動畫。
ImageMagick為Windows應用程序锋八。如果自行安裝的話浙于,在調(diào)用ImageMagick很容易出錯,所以推薦在RStudio里面安裝挟纱。
install.packages("installr")
installr::install.ImageMagick
- 以管理員身份運行RStudio
library(ggplot2)
library(gganimate)
p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length))
+ geom_point()
anim <- p + transition_states(Species,
transition_length = 2, state_length = 1)
animate(anim)