| Title: | Animate 'ggplot2' Plots with 'Anime.js' |
|---|---|
| Description: | Renders 'ggplot2' plots written with 'gganimate' syntax as animated Scalable Vector Graphics (SVG) drawn in the browser by the 'Anime.js' JavaScript library (<https://animejs.com>), through the 'animejs' package. The result is a single self-contained, resolution-independent 'htmlwidget' with one timeline over the plot's elements. |
| Authors: | Long Nguyen [aut, cre] (ORCID: <https://orcid.org/0000-0001-8878-7386>) |
| Maintainer: | Long Nguyen <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-30 12:37:10 UTC |
| Source: | https://github.com/long39ng/gganime |
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.
anime( plot, nframes = 100, fps = 10, duration = NULL, width = 640, height = 480, precision = 2, loop = TRUE, controls = TRUE, elementId = NULL, ... )anime( plot, nframes = 100, fps = 10, duration = NULL, width = 640, height = 480, precision = 2, loop = TRUE, controls = TRUE, elementId = NULL, ... )
plot |
A |
nframes |
Number of frames to sample the animation at. |
fps |
Frames per second, setting the playback speed. |
duration |
Optional total duration in seconds; overrides |
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: |
controls |
Show a play/pause and scrub control bar. |
elementId |
Optional htmlwidget element id. |
... |
Unused; reserved for future arguments. |
An htmlwidget of class gganime.
library(ggplot2) p <- ggplot(iris, aes(Sepal.Width, Sepal.Length, size = Petal.Length)) + geom_point(colour = "steelblue") + labs(title = "{closest_state}") + transition_states(Species) anime(p, nframes = 20)library(ggplot2) p <- ggplot(iris, aes(Sepal.Width, Sepal.Length, size = Petal.Length)) + geom_point(colour = "steelblue") + labs(title = "{closest_state}") + transition_states(Species) anime(p, nframes = 20)
Output and render functions for using gganime widgets within Shiny applications and interactive R Markdown documents.
gganimeOutput(outputId, width = "100%", height = "400px") renderGganime(expr, env = parent.frame(), quoted = FALSE)gganimeOutput(outputId, width = "100%", height = "400px") renderGganime(expr, env = parent.frame(), quoted = FALSE)
outputId |
Output variable to read from. |
width, height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a gganime widget, typically a call
to |
env |
The environment in which to evaluate |
quoted |
Is |
gganimeOutput() returns a Shiny output function for a UI
definition; renderGganime() returns a Shiny render function to assign to
an output slot.
if (interactive() && rlang::is_installed("shiny")) { library(shiny) library(ggplot2) ui <- fluidPage(gganimeOutput("plot")) server <- function(input, output, session) { output$plot <- renderGganime({ anime( ggplot(mtcars, aes(mpg, wt)) + geom_point() + transition_states(gear) ) }) } shinyApp(ui, server) }if (interactive() && rlang::is_installed("shiny")) { library(shiny) library(ggplot2) ui <- fluidPage(gganimeOutput("plot")) server <- function(input, output, session) { output$plot <- renderGganime({ anime( ggplot(mtcars, aes(mpg, wt)) + geom_point() + transition_states(gear) ) }) } shinyApp(ui, server) }