美文网首页
gganimate无法渲染的问题

gganimate无法渲染的问题

作者: 冬之心 | 来源:发表于2023-04-03 11:01 被阅读0次

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()正常显示,必须调用render=gifski_renderer()
  • anim_save()正常保存,必须先返回plot对象,然后print(),最后保存为gif。

4、一种更简单的方法

  • 安装ImageMagick, 让animate()自行调用ImageMagick来显示动画。

  • ImageMagick为Windows应用程序。如果自行安装的话,在调用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)

相关文章

网友评论

      本文标题:gganimate无法渲染的问题

      本文链接:https://www.haomeiwen.com/subject/hpvdddtx.html