2017-08-13 70 views
1

我試圖在包'動畫'中使用函數saveGIF。我已經安裝了所需的外部軟件ImageMagick。審判代碼如下:使用saveGIF在R中創建動畫

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 users Please install ImageMagick from http://www.imagemagick.org , and make sure the the path to convert.exe is in your 'PATH' variable, in which case the commandconvert can be called without the full path. Windows users are often very confused about the ImageMagick and 'PATH' setting, so I'll try to search for ImageMagick in the Registry Hive by readRegistry('SOFTWARE\ImageMagick\Current')$BinPath, thus you might not really need to modify your 'PATH' variable. For Windows users who have installed LyX, I will also try to find the convert utility in the LyX installation directory, so they do not really have to install ImageMagick if LyX exists in their system (of course, the LyX should be installed with ImageMagick). Once the convert utility is found, the animation option 'convert' will be set (ani.options(convert = 'path/to/convert.exe')); this can save time for searching for convert in the operating system next time.

難道錯了我可以理解這些,因爲如果convert.exe的路徑不在我的PATH變量中,我需要指定完整的目錄到convert.exe?

設置或調用convert.exe時是否有問題?

+0

您的代碼在我的R上很好地工作。請仔細檢查路徑「C:\\ Program Files \\ ImageMagick-7.0.6-Q16 \\ convert.exe」是否正確。 –

+0

我在linux上,所以不能測試這個,但我認爲在Windows中你需要引用包含空格的路徑。試試'ani.options(convert =「'C:\\ Program Files \\ ImageMagick-7.0.6-Q16 \\ convert.exe'」) – dww

+0

Marco Sandri,是的,convert.exe的這個路徑的確是正確的。這也是默認的安裝目錄。 – Gamp

回答

-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) 
+0

但結果錯誤 – APD

+0

錯誤:美學必須是長度1或與數據相同(1436):x,y,填充,寬度 另外:警告消息: 1:'panel.margin'已棄用。請使用'panel.spacing'屬性代替 2:'legend.margin'必須使用'margin()'指定。對於舊的行爲使用legend.spacing – APD