I'm trying to caption a gif
as a figure caption (fig.cap
) in a rmarkdown
file so I can reference it in my text. The gif
has been pre-made as opposed to making it within the rmd
file and not sure how to load it back into a chunk. Lets say the following gif was made through an rscript
and saved:
library(gganimate)
aim <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) +
geom_point() +
transition_states(Species,
transition_length = 2,
state_length = 1)
animate(aim)
#save animation
anim_save("testing.gif")
Now if I open an rmd
file and want to insert the gif
I can do the following:
---
title: "testing"
date: "2/26/2020"
output:
bookdown::html_document2
---

this runs but just puts it into the text of the document. I want to give it a fig caption but I cant load the gif
into a chunk, I tried different variations of the following:
```{r giftest, eval=knitr::is_html_output(), echo=F, fig.show = 'animate', fig.cap = "this is testing"}

```
#also tried:
```{r giftest, eval=knitr::is_html_output(), echo=F, fig.show = 'animate', fig.cap = "this is testing",
fig.process= "C:/testing.gif"}
```
#and
```{r, fig.width=4, fig.height=10, fig.cap = "this is testing"}

```
The issue doesnt arise if you make the gif within rmd
but this isnt what I want:
```{r, fig.width=4, fig.height=10, fig.cap = "this is testing"}
library(gganimate)
ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) +
geom_point() +
transition_states(Species,
transition_length = 2,
state_length = 1)
```
any suggestions? thanks