The trio: animation, ggplot and ImageMagick for R version 3.5.0

Hello, try to run a script where I use the libraries animation and ggplot2. But I get the following notice:

I cannot find ImageMagick with convert = "convert"
[1] FALSE
Warning messages:
1: In system(cmd, intern = intern, wait = wait | intern, show.output.on.console = wait,  :
  running command 'C:\WINDOWS\system32\cmd.exe /c convert --version' had status 4
2: In find_magic() : ImageMagick not installed yet!
3: In im.convert(img.files, output = path.expand(movie.name), convert = convert,  :
  Please install ImageMagick first or put its bin path into the system PATH variable

when trying to install the library, the system informs me the following:

install.packages("ImageMagick", dependencies = TRUE, repos = "http://cran.us.r-project.org")
Warning in install.packages :
  package ‘ImageMagick’ is not available (for R version 3.5.0)

What to do?

1 Like

Please install ImageMagick first or put its bin path into the system PATH variable

This refer to a System Requirement not a missing package. {animation} :package: needs the utility ImageMagick or another, as stated in the cran help page

SystemRequirements: ImageMagick (http://imagemagick.org) or GraphicsMagick (http://www.graphicsmagick.org) or LyX (http://www.lyx.org) for saveGIF(); (PDF)LaTeX for saveLatex(); SWF Tools (http://swftools.org) for saveSWF(); FFmpeg (http://ffmpeg.org) or avconv (https://libav.org/avconv.html) for saveVideo()

You should install the windows binary for the package to work.

About animation of ggplot2 graphs, there are also a combination of {gganimate} and {magick} that could do the trick. {magick} :package: use c++ imagemagick so with windows binary there is no system dependency.
An example from this post: https://ropensci.org/blog/2017/08/15/magick-10/

library(gapminder)
library(ggplot2)
library(magick)
img <- image_graph(res = 96)
datalist <- split(gapminder, gapminder$year)
out <- lapply(datalist, function(data){
  p <- ggplot(data, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
    scale_size("population", limits = range(gapminder$pop)) +
    scale_x_log10(limits = range(gapminder$gdpPercap)) +
    geom_point() + ylim(20, 90) +  ggtitle(data$year) + theme_classic()
  print(p)
})
dev.off()
animation <- image_animate(img, fps = 2)
image_write(animation, "animation.gif")

4 Likes