html gif遮住了文字,在rmarkdown HTML输出中禁止GIF的替代文字

本文探讨了在RMarkdown中使用gganimate包生成GIF时遇到的问题:在html_document输出格式下,默认显示alt文本而非GIF。作者尝试解决此问题,并寻求社区帮助以找到更好的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在使用RMarkdown文件中的gganimate包生成GIF。在前端使用output = github_document时,GIF会在输出(github-document-output)中按预期显示。但是,使用output = html_document时,GIF会生成alt文本,默认为块名称(html-document-output)。

有没有办法抑制这个自动标题?我尝试使用fig.cap chunk选项设置我自己的标题,但这不成功。

RMarkdown代码

---

output:

html_document: default

github_document: default

---

```{r}

knitr::opts_chunk$set(

collapse = TRUE,

comment = "#>",

fig.path = "output/test-fig-",

cache.path = "output/test-cache-"

)

```

```{r cache = FALSE}

library(knitr)

library(animation)

ani.options(autobrowse = FALSE, interval = 1)

opts_knit$set(animation.fun = function(x, options, format = "gif") {

x = c(knitr:::sans_ext(x), knitr:::file_ext(x))

fig.num = options$fig.num

format = sub("^[.]", "", format)

fig.fname = paste0(sub(paste0(fig.num, "$"), "*", x[1]),

".", x[2])

mov.fname = paste0(sub(paste0(fig.num, "$"), "", x[1]), ".",

format)

# order correctly

figs

figs

animation::im.convert(figs, output = mov.fname)

sprintf("![%s](%s)", options$label, paste0(opts_knit$get("base.url"), mov.fname))

})

opts_chunk$set(cache = TRUE, message = FALSE, warning = FALSE, fig.show = "animate")

```

```{r pkgs, cache = FALSE}

library(gapminder)

library(ggplot2)

theme_set(theme_bw())

```

```{r setup}

p

geom_point() +

scale_x_log10()

```

```{r dependson = "setup"}

library(gganimate)

gg_animate(p)

```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值