【问题标题】:use saveGIF to create animation in R使用 saveGIF 在 R 中创建动画
【发布时间】:2017-08-13 18:50:56
【问题描述】:

我试图在包 '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 中的 Notes 中注明

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

如果我的 PATH 变量中没有 convert.exe 的路径,我可以理解这些是否错了,我需要指定 convert.exe 的完整目录?

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

【问题讨论】:

  • 您的代码在我的 R 上运行良好。仔细检查路径 C:\\Program Files\\ImageMagick-7.0.6-Q16\\convert.exe 是否正确。
  • 我在 linux 上,所以无法对此进行测试,但我认为在 Windows 中,您需要在包含空格的路径周围加上引号。试试ani.options(convert = "'C:\\Program Files\\ImageMagick-7.0.6-Q16\\convert.exe'")
  • Marco Sandri,是的,这个 convert.exe 的路径确实是正确的。这也是默认的安装目录。
  • dww,不,不在这里。试过但出错

标签: r windows animation


【解决方案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)

【讨论】:

  • 错误:美学必须是长度 1 或与数据 (1436) 相同:x、y、填充、宽度此外:警告消息:1:panel.margin 已弃用。请改用panel.spacing 属性 2:必须使用margin() 指定legend.margin。对于旧行为,请使用 legend.spacing
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-23
  • 1970-01-01
  • 2021-11-29
  • 2018-08-25
  • 2021-01-23
  • 2020-02-25
  • 1970-01-01
相关资源
最近更新 更多