2

I have some ggplot objects animated via gganimate, and I would like to change the speed of the animation.

Here is a reproducible example from the github repo here: https://github.com/dgrtwo/gganimate

library(gapminder)
library(ggplot2)
theme_set(theme_bw())

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
    geom_point() +
    scale_x_log10()

library(gganimate)
gganimate(p)

This animation takes about 12 seconds to cycle all the way through. How could I make it cycle through in say 6 seconds?

I have tried setting time to different values, but to no avail, and it is not clear from the help page.

gganimate(p, time = 0.1)

Update

The interval seems to generally work, but still unclear to me how I could make this work within an Rmarkdown report. As an example, if I place the code below in a file called test.R and then run rmarkdown::render('test.R') my animation runs at the default speed instead of the expected increased speed. How would I make this work in the context of rmarkdown::render? I've been trying various things from looking here: https://github.com/dgrtwo/gganimate/commit/3aa2064cdfff30feb2b00724ad757fd5a5a62621, but to no avail.

knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.show = 'animate')

library(gapminder)
library(ggplot2)
theme_set(theme_bw())

p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
    geom_point() +
    scale_x_log10()

library(gganimate)
capture.output(gganimate(p, interval = 0.2))
jmuhlenkamp
  • 2,102
  • 1
  • 14
  • 37
  • 1
    Per the end of [the README](https://github.com/dgrtwo/gganimate), you need to set the `interval` chunk option, e.g. `{r my-animation, interval = 1/60}` – alistaire Mar 15 '18 at 17:24

1 Answers1

2

We need to set interval option:

gganimate(p, interval = 0.2)

From animation package manual, see ani.options:

interval a positive number to set the time interval of the animation (unit in seconds); default to be 1.

zx8754
  • 52,746
  • 12
  • 114
  • 209