我正在尝试将 gif
标题作为 rmarkdown
文件中的图形标题 (fig.cap
),以便我可以引用它在我的文字中。 gif
已预先制作,而不是在 rmd
文件中制作,并且不确定如何将其加载回 block 中。假设以下 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
加载到一个 block 中,我尝试了以下不同的变体:
```{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 - 将预制的 gganimate gif 加载到 rmarkdown block 中作为标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60420075/