renderers {gganimate} | R Documentation |
Renderers provided by gganimate
Description
The purpose of the renderer function is to take a list of image files and
assemble them into an animation. gganimate
provide a range of renderers
but it is also possible to provide your own, if the supplied ones are lacking
in any way. A renderer is given as argument to animate()
/print() and
receives the paths to the individual frames once they have been created.
Usage
gifski_renderer(file = NULL, loop = TRUE, width = NULL, height = NULL)
file_renderer(dir = ".", prefix = "gganim_plot", overwrite = FALSE)
av_renderer(file = NULL, vfilter = "null", codec = NULL, audio = NULL)
ffmpeg_renderer(
format = "auto",
ffmpeg = NULL,
options = list(pix_fmt = "yuv420p")
)
magick_renderer(loop = TRUE)
sprite_renderer()
Arguments
file |
The animation file |
loop |
Logical. Should the produced gif loop |
width , height |
Dimensions of the animation in pixels. If |
dir |
The directory to copy the frames to |
prefix |
The filename prefix to use for the image files |
overwrite |
Logical. If TRUE, existing files will be overwritten. |
vfilter |
A string defining an ffmpeg filter graph. This is the same
parameter as the |
codec |
The name of the video codec. The default is |
audio |
An optional file with sounds to add to the video |
format |
The video format to encode the animation into |
ffmpeg |
The location of the |
options |
Either a character vector of command line options for ffmpeg or a named list of option-value pairs that will be converted to command line options automatically |
Details
The gifski_renderer()
is used unless otherwise specified in
animate()
or in options('gganimate.renderer')
. This renderer requires
both the gifski
and png
packages to be installed.
Other possible renderers are:
-
magick_renderer()
which requires themagick
package and produce agif
. Ifgifski
is not installed, the rendering will be much slower than using thegifski_renderer()
and can potentially result in system problems when many frames need to be rendered (ifgifski
is installedmagick
will use it under the hood) -
av_renderer()
which requies theav
package and uses ffmpeg to encode the animation into a video file. -
ffmpeg_renderer()
which requires that ffmpeg has been installed on your computer. As withav_renderer()
it will use ffmpeg to encode the animation into a video -
sprite_renderer()
which requiresmagick
and will render the animation into a spritesheet -
file_renderer()
which has no dependencies and simply returns the animation as a list of image files (one for each frame)
It is possible to create your own renderer function providing that it
matches the required signature (frames
and fps
argument). The return
value of your provided function will be the return value ultimately given by
animate()
Value
The provided renderers are factory functions that returns a new function
that take frames
and fps
as arguments, the former being a character
vector with file paths to the images holding the separate frames, in the
order they should appear, and the latter being the framerate to use for the
animation in frames-per-second.
The return type of the different returned renderers are:
-
gifski_renderer
: Returns a gif_image object -
magick_renderer
: Returns amagick-image
object -
av_renderer
: Returns a video_file object -
ffmpeg_renderer
: Returns a video_file object -
file_renderer
: Returns a vector of file paths
Examples
anim <- ggplot(mtcars, aes(mpg, disp)) +
transition_states(gear, transition_length = 2, state_length = 1) +
enter_fade() +
exit_fade()
## Not run:
# Renderers are specified in the `animate()` function
animate(anim, renderer = sprite_renderer())
## End(Not run)