2017-08-03 98 views
1

我正尝试在Windows 7计算机的RStudio 0.98.1102中使用R 3.1.3的'animate'包。我已经安装了ImageMagick,如果我写下面几行,我会得到一个动画gif文件。R中的'动画'包将状态保存为GIF 127

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),而不会产生任何错误消息。我将非常感谢您对上述问题的反馈,建议和解决方案。

回答

0

该代码适用于我。你安装了ImageMagick吗?这是需要gganimate请参阅这里的指示:https://rpubs.com/sjackman/gapminder-gganimate

+0

是的,我已经安装ImageMagick和工程。我已经使用过系统(“magick -delay 80 * .png example_1.gif”)来生成一个gif文件。 –