gganimate无法渲染的问题

2023-04-03  本文已影响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)

4、一种更简单的方法

install.packages("installr")
installr::install.ImageMagick
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)

上一篇 下一篇

猜你喜欢

热点阅读