Skip to contents

Builds a ggplot2 plot written with gganimate syntax and renders it as a self-contained, resolution-independent animated-SVG htmlwidget powered by Anime.js, instead of gganimate's frame-by-frame output.

Usage

anime(
  plot,
  nframes = 100,
  fps = 10,
  duration = NULL,
  width = 640,
  height = 480,
  precision = 2,
  loop = TRUE,
  controls = TRUE,
  elementId = NULL,
  ...
)

Arguments

plot

A gganim plot: a ggplot2 plot with a transition_*() added.

nframes

Number of frames to sample the animation at.

fps

Frames per second, setting the playback speed.

duration

Optional total duration in seconds; overrides fps.

width, height

Widget size in pixels, defaulting to 640 by 480. The plot is rendered at these dimensions, so their ratio sets the plot's aspect ratio.

precision

Decimal places to round animated coordinates to.

loop

Loop the animation: TRUE, FALSE, or a number of iterations.

controls

Show a play/pause and scrub control bar.

elementId

Optional htmlwidget element id.

...

Unused; reserved for future arguments.

Value

An htmlwidget of class gganime.

Examples

library(ggplot2)

p <- ggplot(iris, aes(Sepal.Width, Sepal.Length, size = Petal.Length)) +
  geom_point(colour = "steelblue") +
  labs(title = "{closest_state}") +
  transition_states(Species)

# \donttest{
anime(p, nframes = 20)
# }