使用saveGIF在R中创建动画

时间:2017-08-13 18:50:57

标签: r windows animation

我试图在包'动画'中使用saveGIF功能。 。我已经安装了所需的外部软件ImageMagick。试用代码如下:

library(animation)

ani.options(convert = 'C:\\Program Files\\ImageMagick-7.0.6-Q16\\convert.exe')
saveGIF({
  for (i in 1:10) plot(runif(10), ylim = 0:1)
})

但它会出现以下错误:

Executing: 
"C:\Program Files\ImageMagick-7.0.6-Q16\convert.exe -loop 0 -delay 100
    Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png
    Rplot8.png Rplot9.png Rplot10.png "animation.gif""
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
an error occurred in the conversion... see Notes in ?im.convert
Warning messages:
1: running command 'C:\WINDOWS\system32\cmd.exe /c "C:\Program Files\ImageMagick-7.0.6-Q16\convert.exe -loop 0  -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif""' had status 1 
2: In cmd.fun(convert) :
  '"C:\Program Files\ImageMagick-7.0.6-Q16\convert.exe -loop 0  -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif""' execution failed with error code 1
3: running command '"C:\Program Files\ImageMagick-7.0.6-Q16\convert.exe -loop 0  -delay 100 Rplot1.png Rplot2.png Rplot3.png Rplot4.png Rplot5.png Rplot6.png Rplot7.png Rplot8.png Rplot9.png Rplot10.png "animation.gif""' had status 127 

从?im.convert

中的注释注意到
  

ImageMagick用户请从http://www.imagemagick.org安装ImageMagick,并确保convert.exe的路径   在你的路径中#39;变量,在这种情况下commandconvert可以   没有完整路径就叫。 Windows用户经常非常困惑   关于ImageMagick和' PATH'设置,所以我会尝试搜索   ImageMagick在Registry Hive中   readRegistry(' SOFTWARE \ ImageMagick \ Current')$ BinPath,因此你可能会   不需要修改你的路径'变量。适用于Windows用户   已经安装了LyX,我也会尝试在中找到转换实用程序   LyX安装目录,所以他们真的不必安装   ImageMagick如果LyX存在于他们的系统中(当然,LyX应该   与ImageMagick一起安装)。找到转换实用程序后,即可   动画选项'转换'将被设置(ani.options(转换=   '路径/到/ CONVERT.EXE'));这可以节省搜索转换的时间   在下次操作系统中。

是不是我可以理解这些因为如果convert.exe的路径不在我的PATH变量中,我需要指定convert.exe的完整目录?

设置或调用convert.exe有什么问题吗?

1 个答案:

答案 0 :(得分:-1)

saveGIF({

  for (i in dflaser10sec1$seg) {

    title <- as.character(i)

    g1 <- ggplot(dflaser10sec1, aes(x = dflaser10sec1$value, y = dflaser10sec1$pos, fill = dflaser10sec1$pos, width = 1)) +
      coord_fixed() +
      coord_flip() +
      annotate('text', x = 98, y = -800000, 
               label = 'Laser PROFILE', size = 3) +
      geom_bar(data = subset(dflaser10sec1, pos == "9"), stat = "identity") +
      geom_bar(data = subset(dflaser10sec1, pos == "10"),  stat = "identity") +
      theme_economist(base_size = 14) + 
      scale_fill_manual(values = c('#ff9896', '#d62728')) + 
      ggtitle(paste0('profile of the laser setup, ', title)) + 
      ylab('Value') + 
      xlab('Laser Position') + 
      theme(legend.position = "bottom", legend.title = element_blank()) + 
      guides(fill = guide_legend(reverse = TRUE))

    print(g1)

  }

}, movie.name = 'laser.gif', interval = 0.1, ani.width = 700, ani.height = 600)
相关问题