我正在尝试在 Windows 7 计算机的 RStudio 0.98.1102 中使用 R 3.1.3 的“动画”包。我已经安装了 ImageMagick,如果我写了以下几行,我会得到一个动画 gif 文件。
library(animation)
ani.options('C:/Program Files/ImageMagick-7.0.4-Q16/convert.exe')
png(file="example%02d.png",width=200, height=200)
for(i in c(10:1,"GO!")){
plot.new()
text(.5,.5,i,cex=6)
}
dev.off()
system("magick -delay 80 *.png example_1.gif")
到目前为止,一切都很好。但是当我尝试使用 gganimate 包时遇到问题。我刚刚从动画包的github页面复制了以下几行:
library(gapminder)
library(ggplot2)
theme_set(theme_bw())
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color =
continent, frame = year)) +
geom_point() +
scale_x_log10()
library(gganimate)
gganimate(p)
执行完最后一行后,出现以下错误:
现在,我编写以下命令并再次运行以获取类似的错误消息,并且没有生成 gif 文件:
ani.options(convert = shQuote('C:/Program Files/ImageMagick-7.0.4-
Q16/magick.exe'))
gganimate(p)
现在,如果我写下面的行,我会收到错误消息,但会生成一个动画 gif 文件。
ani.options(convert = shQuote('C:/Program Files/ImageMagick-7.0.4-
Q16/magick.exe'))
gganimate(p, "output.gif")
RStudio 中没有显示动画,我必须找到保存新 gif 文件的工作目录的位置。
我不明白为什么会发生这种情况以及如何使用 gganimate() 生成 .gif(在 RStudio 内部)而不会生成任何错误消息。我将非常感谢您对上述问题的反馈、建议和解决方案。