Skip to content

Instantly share code, notes, and snippets.

@thomasp85
Created October 11, 2018 19:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasp85/14ed997191f7c6d363517a4dd89f090b to your computer and use it in GitHub Desktop.
Save thomasp85/14ed997191f7c6d363517a4dd89f090b to your computer and use it in GitHub Desktop.
An example of embedding a gganimate animation in a pdf
---
title: "PDF Animation Test"
output: pdf_document
header-includes:
- \usepackage{animate}
---
`gganimate` now supports animations inside PDF documents. This feature is only
viewable with Acrobat Reader, however. Remember to include
`\usepackage{animate}` in the preamble and set `fig.show='animate'` in the chunk
options. Further, the framerate is governed by `interval`rather than any
`gganimate` settings:
```{r, fig.show='animate', interval=1/10}
library(gganimate)
ggplot(airquality, aes(Day, Temp, group = Month)) +
geom_line() +
transition_reveal(Month, Day)
```
@Frank-Sw
Copy link

One minor comment: here the knitr should use the development version, else unable to work, at least to me already.

Source: https://stackoverflow.com/questions/52884403/issue-knitting-to-a-pdf-document-using-gganimate-animation-not-included

@thiyangt
Copy link

thiyangt commented Mar 29, 2019

image

Is there a way to remove the control buttons? R chunk options are fig.show='animate',out.width="60%", interval=1/10,
and the code is

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')

@MauricioCely
Copy link

Is it possible to get and html_document output with controls? Similar as done in the PDF document.

@manolo20
Copy link

manolo20 commented Jul 22, 2020

You might also want to use transition_reveal(Month) in line 18 instead of transition_revel(Month, Day) as indicated thomasp85/gganimate#270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment