【发布时间】:2020-06-10 16:33:10
【问题描述】:
我正在尝试在 rmarkdown 文件中为 gif 加上图形标题 (fig.cap),以便在我的文本中引用它。 gif 是预先制作的,而不是在 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
---

这会运行,但只是将其放入文档的文本中。我想给它一个无花果标题,但我无法将gif 加载到一个块中,我尝试了以下不同的变体:
```{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"}

```
如果您在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 r-markdown gganimate