【问题标题】:load premade gganimate gif into rmarkdown chunk to caption将预制的 gganimate gif 加载到 rmarkdown 块中以添加标题
【发布时间】: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
---

![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 r-markdown gganimate


    【解决方案1】:

    以下代码块适用于我:

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

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-22
      相关资源
      最近更新 更多