gganimate

A Grammar of Animated Graphics

https://github.com/thomasp85/gganimate

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    4 of 30 committers (13.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.9%) to scientific vocabulary

Keywords

animation data-visualization ggplot-extension ggplot2 rstats transition

Keywords from Contributors

tidy-data geos tidyverse setup visualisation genome gdal package-creation grammar data-manipulation
Last synced: 6 months ago · JSON representation

Repository

A Grammar of Animated Graphics

Basic Info
  • Host: GitHub
  • Owner: thomasp85
  • License: other
  • Language: R
  • Default Branch: main
  • Homepage: https://gganimate.com
  • Size: 54.7 MB
Statistics
  • Stars: 1,976
  • Watchers: 58
  • Forks: 314
  • Open Issues: 84
  • Releases: 13
Topics
animation data-visualization ggplot-extension ggplot2 rstats transition
Created about 10 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Code of conduct

README.Rmd

---
output: github_document
---



```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  gganimate = list(
    nframes = 50
  )
)
```

# gganimate 


[![R-CMD-check](https://github.com/thomasp85/gganimate/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/thomasp85/gganimate/actions/workflows/R-CMD-check.yaml)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version-ago/gganimate)](https://cran.r-project.org/package=gganimate)
[![CRAN_Download_Badge](http://cranlogs.r-pkg.org/badges/gganimate)](https://cran.r-project.org/package=gganimate)
[![Codecov test coverage](https://codecov.io/gh/thomasp85/gganimate/graph/badge.svg)](https://app.codecov.io/gh/thomasp85/gganimate)


`gganimate` extends the grammar of graphics as implemented by
[`ggplot2`](https://github.com/tidyverse/ggplot2) to include the description of
animation. It does this by providing a range of new grammar classes that can be
added to the plot object in order to customise how it should change with time.

- `transition_*()` defines how the data should be spread out and how it relates
  to itself across time.
- `view_*()` defines how the positional scales should change along the
  animation.
- `shadow_*()` defines how data from other points in time should be presented in
  the given point in time.
- `enter_*()`/`exit_*()` defines how new data should appear and how old data
  should disappear during the course of the animation.
- `ease_aes()` defines how different aesthetics should be eased during
  transitions.

## An Example
All of the above might seem a bit abstract. Let's try with a contrived example:

```{r, message=FALSE}
library(ggplot2)
library(gganimate)

ggplot(mtcars, aes(factor(cyl), mpg)) +
  geom_boxplot() +
  # Here comes the gganimate code
  transition_states(
    gear,
    transition_length = 2,
    state_length = 1
  ) +
  enter_fade() +
  exit_shrink() +
  ease_aes('sine-in-out')
```

Here we take a simple boxplot of fuel consumption as a function of cylinders and
lets it transition between the number of gears available in the cars. As this is
a discrete split (`gear` being best described as an ordered factor) we use
`transition_states` and provides a relative length to use for transition and
state view. As not all combinations of data is present there are states missing
a box. We define that when a box appears it should fade into view, whereas at
should shrink away when it disappear. Lastly we decide to use a sinusoidal
easing for all our aesthetics (here, only `y` is changing)

## Installation
`gganimate` is available on CRAN and can be installed with
`install.packages('gganimate')`. If you wish to install the development version
you can install directly from github using devtools:

```{r, eval=FALSE}
# install.packages('pak')
pak::pak('thomasp85/gganimate')
```

## Yet Another Example
It is impossible to cover everything possible with `gganimate` in a README, but
animations are fun, so let's at least have one more:

```{r}
library(gapminder)

ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = country)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_colour_manual(values = country_colors) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  facet_wrap(~continent) +
  # Here comes the gganimate specific bits
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')
```

In this example we see the use of `transition_time()` which can be used with
continuous variables such as `year`. With this transition it is not necessary to
provide transition and state length as the "transition variable" provides this
directly (e.g. it should take twice as long to transition between 1980 and 1990
compared to 2000 to 2005). We also see the use of string literal interpolation
in titles. `gganimate` lets you specify variables to evaluate inside titles and
different transitions provide different type of information to use.

## Where is my animation?
`gganimate` mimics the way `ggplot2` renders its output, in that the rendering
is done automatically when the `gganim` object is printed. Under the hood, the
`animate()` function is called which renders the frame and passes the frames to
a renderer functions which takes care of combining them to the final animation.
The default renderer is `gifski_renderer()` which returns a `gif_image` object
which is a simple wrapper around a path to a gif file. If `animate()` has been
called implicitly as part of `print` the `gif_image` object is available using
the `last_animation()` function (analogous to `ggplot2::last_plot()`). In order
to save the animation to a specific location, you can use the `anim_save()`
function which, like `ggplot2::ggsave`, defaults to taking the last rendered
animation and writes it to a file.

## I don't like gifs...
gif is a fantastic format for animations due to its wide support, but sometimes
another format is required. `gganimate` is agnostic to the renderer and while
the default is to use [gifski](https://github.com/r-rust/gifski) to combine the
frames into a gif, it doesn't have to be so. By passing an alternate renderer to
the `animate()` function you can control the animation format, and `gganimate`
comes with a bunch (and you can write your own). To create video files you can
e.g. use the `ffmpeg_renderer()`:

```{r, eval=FALSE}
p <- ggplot(airquality, aes(Day, Temp)) +
  geom_line(size = 2, colour = 'steelblue') +
  transition_states(Month, 4, 1) +
  shadow_mark(size = 1, colour = 'grey')
animate(p, renderer = ffmpeg_renderer())
```

*Video output are automatically embedded in RMarkdown documents, but GitHub strips video when rendering READMEs so you can't see it here*

Further there's support for rendering to sprite sheets if that is your vice.

## Old API
This is the second iteration of the gganimate package. The first, developed by
[David Robinson](https://github.com/dgrtwo) had a very different API, and relied
on specifying animation frame membership inside `aes()` blocks in the `geom_*()`
calls. This approach was easy to grasp, but essentially limited in capabilities
and has thus been abandoned for a more thorough grammar.

Code written for the old API will not work with this `gganimate` version and
there will not come a future support for it. If you wish to continue using the
old API then avoid upgrading `gganimate`. If you've already upgraded and wish to
downgrade, the latest version of the old API is available as a
[GitHub release](https://github.com/thomasp85/gganimate/releases/tag/v0.1.1).

If you wish to convert your old animations to the new API, the closest you get
is probably with `transition_manual`, even though it is not completely
substitutable:

```{r, eval=FALSE}
# Old code
ggplot(mtcars) +
  geom_boxplot(aes(factor(cyl), mpg, frame = gear))

# New code
ggplot(mtcars) +
  geom_boxplot(aes(factor(cyl), mpg)) +
  transition_manual(gear)
```

Owner

  • Name: Thomas Lin Pedersen
  • Login: thomasp85
  • Kind: user
  • Location: Copenhagen
  • Company: @posit-pbc, part of @tidyverse team

Maker of tools focusing on data science and data visualisation

GitHub Events

Total
  • Create event: 1
  • Release event: 1
  • Issues event: 16
  • Watch event: 40
  • Member event: 1
  • Issue comment event: 22
  • Push event: 17
  • Pull request event: 5
  • Fork event: 7
Last Year
  • Create event: 1
  • Release event: 1
  • Issues event: 16
  • Watch event: 40
  • Member event: 1
  • Issue comment event: 22
  • Push event: 17
  • Pull request event: 5
  • Fork event: 7

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 428
  • Total Committers: 30
  • Avg Commits per committer: 14.267
  • Development Distribution Score (DDS): 0.117
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Thomas Lin Pedersen t****5@g****m 378
dgrtwo d****o@p****u 8
Dave Robinson d****n@s****m 8
Alper Yilmaz a****z@g****m 2
Jeroen Ooms j****s@g****m 2
Jim Hester j****r@g****m 2
Kanishka m****e@g****m 2
Michael Chirico m****4@g****m 2
Teun van den Brand 4****d 2
khailper k****r 2
Mickaël Canouil m****l@c****r 1
Carson Sievert c****1@g****m 1
Claus Wilke w****e@a****u 1
David F. Severski d****i 1
David Robinson a****d@g****m 1
Dmytro Perepolkin d****n@g****m 1
Ezequiel Paura e****a@g****m 1
Howard Baek 5****k 1
Jacob Wujciak-Jens g****b@k****e 1
Jay Hesselberth j****h@g****m 1
Joel Kitching j****l@j****a 1
Kevin Zen k****s@u****u 1
Pierre Roudier p****r@g****m 1
Rick Saporta R****a@g****m 1
Stefan Schreiber s****r 1
Victor Ordu v****u@o****m 1
Yihui Xie x****e@y****e 1
rfaelens r****s@g****m 1
tjebo 3****o 1
yunching y****m@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 127
  • Total pull requests: 22
  • Average time to close issues: 12 months
  • Average time to close pull requests: 8 months
  • Total issue authors: 99
  • Total pull request authors: 11
  • Average comments per issue: 2.19
  • Average comments per pull request: 1.41
  • Merged pull requests: 10
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 15
  • Pull requests: 5
  • Average time to close issues: 17 days
  • Average time to close pull requests: about 1 month
  • Issue authors: 13
  • Pull request authors: 1
  • Average comments per issue: 0.27
  • Average comments per pull request: 0.4
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • thomasp85 (17)
  • bbcuffer (5)
  • py9mrg (3)
  • gudryan (2)
  • katrinabrock (2)
  • saeeshm (2)
  • neuwirthe (2)
  • mccarthy-m-g (2)
  • cderv (2)
  • banbh (1)
  • emcbride09 (1)
  • dgraetz (1)
  • LukasWallrich (1)
  • yutannihilation (1)
  • abiyug (1)
Pull Request Authors
  • teunbrand (7)
  • MichaelChirico (4)
  • espinielli (2)
  • aminadibi (2)
  • HenrikBengtsson (1)
  • jkitching (1)
  • the-mad-statter (1)
  • rrmn (1)
  • assignUser (1)
  • jeroen (1)
  • coolbutuseless (1)
Top Labels
Issue Labels
bug (22) enhancement (19) Documentation (10) reprex (8) question (7) transitions (5) shadows (4) views (3) enter/exit (1) duplicate (1)
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • cran 16,818 last-month
  • Total docker downloads: 48,160
  • Total dependent packages: 39
    (may contain duplicates)
  • Total dependent repositories: 111
    (may contain duplicates)
  • Total versions: 20
  • Total maintainers: 1
cran.r-project.org: gganimate

A Grammar of Animated Graphics

  • Versions: 12
  • Dependent Packages: 39
  • Dependent Repositories: 109
  • Downloads: 16,818 Last month
  • Docker Downloads: 48,160
Rankings
Stargazers count: 0.1%
Forks count: 0.1%
Dependent packages count: 2.0%
Dependent repos count: 2.1%
Downloads: 3.3%
Average: 5.2%
Docker downloads count: 23.5%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: r-gganimate
  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 2
Rankings
Stargazers count: 9.2%
Forks count: 9.9%
Dependent repos count: 20.2%
Average: 22.7%
Dependent packages count: 51.6%
Last synced: 6 months ago