将预制的 gganimate gif 加载到 rmarkdown 块中以添加标题

load premade gganimate gif into rmarkdown chunk to caption

我正在尝试在 rmarkdown 文件中将 gif 的标题作为图形标题 (fig.cap),以便我可以在我的文本中引用它。 gif 已经 pre-made 而不是在 rmd 文件中,并且不确定如何将它加载回块中。假设以下 gif 是通过 rscript 制作并保存的:

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

现在,如果我打开一个 rmd 文件并想插入 gif,我可以执行以下操作:

---
title: "testing"
date: "2/26/2020"
output:
  bookdown::html_document2
---

![this is testing](C:/testing.gif)

这会运行,但只是将其放入文档的文本中。我想给它一个无花果标题,但我无法将 gif 加载到一个块中,我尝试了以下不同的变体:

```{r giftest, eval=knitr::is_html_output(), echo=F, fig.show = 'animate', fig.cap = "this is testing"}

![](C:/testing.gif)
```

#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"}
![](C:/testing.gif)
```

如果在 rmd 内制作 gif 就不会出现问题,但这不是我想要的:

```{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)

```

有什么建议吗?谢谢

以下代码块适合我:

```{r testing, fig.cap="example caption"}
knitr::include_graphics("testing.gif")
```