anim_save() renders a vellum_animation (from animate()) to an animated
image, tweening the frames between keyframes and encoding them in one parallel,
streaming pass in vellum's Rust backend. The format follows the file extension:
Arguments
- filename
Output path;
.gif,.png/.apng, or.svg.- animation
A
vellum_animation(fromanimate()).
Details
.gif— a looping GIF (universal compatibility)..pngor.apng— an animated PNG (APNG; lossless, alpha). Browsers play either;.pngis the more widely recognised extension, and image viewers that do not know APNG show its first frame..svg— a single animated SVG: every frame is emitted as vector markup and shown in turn by a CSS step animation. It is resolution-independent (crisp at any size, in print and on retina) and honoursprefers-reduced-motion(a reader who has asked their system not to animate gets the first frame, held).
Choosing a format
Pick by scene complexity, not preference. An animated SVG emits every frame in
full, so its size grows with the number of marks times the number of frames;
a raster format (GIF/APNG) does not. So SVG wins clearly on line art — a few
moving marks, the common explanatory case — and loses on a dense scatter, where
a raster format is the right answer. anim_save() says so when a .svg scene
is dense enough that a raster format would likely be smaller.
Video (.mp4, .webm, ...) and animated WebP are not written: there is no
encoder for them among vellum's dependencies. Save an APNG or GIF and
convert it, e.g. ffmpeg -i anim.png -pix_fmt yuv420p anim.mp4, or
magick::image_write(magick::image_read("anim.gif"), "anim.webp").
Examples
if (FALSE) { # \dontrun{
# Four bars in every state, so each bar tweens into its next height.
d <- data.frame(t = rep(1:3, each = 4), g = rep(letters[1:4], 3),
v = c(1, 3, 2, 4, 4, 1, 3, 2, 2, 4, 1, 3))
a <- vplot(d) |>
mark_bar(x = g, y = v, fill = g) |>
transition_states(t) |>
animate()
anim_save("bars.gif", a)
anim_save("bars.svg", a) # resolution-independent
} # }
