Using LaTeX Animation Package in RMarkdown

I would like to generate animated graphics in PDF using the LaTeX animate package .

The code

---
title: "test_animations"
author: "Colours"
date: "27/10/2017"
output: 
    pdf_document:
        includes:
            in_header: header_ani.tex

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
pacman::p_load(gganimate, gapminder, ggplot2)
```

## Test animations

```{r sample_ani, fig.show='animate', message=FALSE, warning=FALSE}
p2 <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop)) +
  geom_point() +
  geom_point(aes(frame = year), color = "red") +
  scale_x_log10()
gganimate(p2, saver = "gif")
```

header_ani.tex

\usepackage{animate}

Problem

Warning: ignoring unknown aesthetics: frame

Exiting lines 20-25 (second_animation.Rmd) Error: Could not find ffmpeg command. You must either change the animation. or install ffmpeg with libvpx enabled. Execution paused

Notes

Why link to . According to the knitr documentation :

chunk fig.show = 'animate' , . LaTeX LaTeX PDF. HTML/Markdown FFmpeg WebM. , libvpx FFmpeg. Linux Windows - FFmpeg (libvpx ). OS X FFmpeg Homebrew

html. - RMarkdown?

enter image description here

(RStudio: RMarkdown)

ffmpeg - ?

RMarkdown , PDF , .

chart with controls

( , , , PDF, , ).

+4
1

( knitr rmarkdown) , LaTeX :

---
title: "test_animations"
author: "Colours"
date: "27/10/2017"
classoption: landscape
output: 
    pdf_document:
        keep_tex: true
        includes:
            in_header: header_ani.tex

---

```{r setup, include=FALSE}
Vectorize(require)(package = c("knitr"),
               character.only = TRUE)
opts_chunk$set(echo = FALSE,
               cache = TRUE)
pacman::p_load(gganimate, gapminder, ggplot2)
```

## Test animations

```{r sample_ani, message=TRUE, warning=TRUE, echo=TRUE, }
p2 <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop)) +
  geom_point() +
  geom_point(aes(frame = year), color = "red") +
  scale_x_log10()
gganimate(p2, filename = "animation2.gif", title_frame = TRUE) -> amimate
```
<!-- Notes on the answer: https://tex.stackexchange.com/a/240387/123504 -->

```{r convert_shele, echo=TRUE, message=TRUE, warning=TRUE, paged.print=FALSE}
# Extra options for resize can be added
system(command = "convert -coalesce animation2.gif something.png")
```


  \animategraphics[loop,controls,width=\linewidth]{12}{something-}{0}{12}

# Latex code generating animation

Figures 0 - 12 should reflect frames

~~~
  \animategraphics[loop,controls,width=\linewidth]{12}{something-}{0}{12}
~~~

. .

.

view generated animation

  • convert. , , .
  • {12}{something-}{0}{12} , ( ) something- , convert, something-0.png ... something-n.png {0}{12} .
+2

Source: https://habr.com/ru/post/1688303/


All Articles