【问题标题】:'animation' package in R saves GIF with status 127R中的“动画”包保存状态为127的GIF
【发布时间】:2018-01-11 14:53:15
【问题描述】:

我正在尝试在 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)

执行最后一行后,出现如下错误:

error message 1

现在,我编写以下命令并再次运行以得到类似的错误消息,并且没有生成 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")

error message 3

RStudio 中没有显示动画,我必须找到保存新 gif 文件的工作目录的位置。

我不明白为什么会发生这种情况以及如何使用 gganimate() 生成 .gif(在 RStudio 内部)而不生成任何错误消息。我将非常感谢您对上述问题的反馈、建议和解决方案。

【问题讨论】:

    标签: r gganimate


    【解决方案1】:

    代码对我有用。你安装了 ImageMagick 吗? gganimate 需要它,请参阅此处了解说明:https://rpubs.com/sjackman/gapminder-gganimate

    【讨论】:

    • 是的,我已经安装了 ImageMagick 并且可以正常工作。我已经使用 system("magick -delay 80 *.png example_1.gif") 生成了一个 gif 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2014-09-01
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 2018-11-13
    相关资源
    最近更新 更多