I am trying to produce an animated plot with gganimate
following instructions from the knitr documentation:
knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.show = "animate")
# Example from https://github.com/dgrtwo/gganimate
library(ggplot2)
library(gganimate)
# For example, suppose we wanted to create an animation similar to the Gapminder
# world animation, using Jenny Bryan's gapminder package for the data.
library(gapminder)
theme_set(theme_bw())
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
geom_point() +
scale_x_log10()
# Notice we added frame = year and saved the plot as p.
# We then display it as an animation with the gg_animate function:
gg_animate(p)
However, I am getting the error:
Error: Could not find ffmpeg command. You should either change the animation.fun hook option or install ffmpeg with libvpx enabled.
I have followed the instructions here to install ffmpeg, and running ffmpeg -version
in the command line gives:
C:\ffmpeg\bin>ffmpeg -version
ffmpeg version 3.2.2 Copyright (c) 2000-201
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-versio
nable-nvenc --enable-avisynth --enable-bzli
--enable-gnutls --enable-iconv --enable-li
s2b --enable-libcaca --enable-libfreetype -
le-libilbc --enable-libmodplug --enable-lib
enable-libopencore-amrwb --enable-libopenh2
pus --enable-librtmp --enable-libsnappy --e
ble-libtheora --enable-libtwolame --enable-
enable-libvorbis --enable-libvpx --enable-l
ibx264 --enable-libx265 --enable-libxavs --
ble-lzma --enable-decklink --enable-zlib
libavutil 55. 34.100 / 55. 34.100
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.100 / 57. 56.100
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
What should I do now? In particular, what does it mean to 'change the animation.fun hook option'?
EDIT: I have just noticed that system('ffmpeg -version')
returns a 127 status code, but works fine from my command line.
A restart of
Rstudio
and presumably the underlyingRsession
fixed the problem.