在 R Markdown 中,我尝试为图像添加标题,但没有显示。下面是使用 RStudio 和“Knit to HTML”的 HTML 代码和屏幕截图。没有标题,即使它在括号中。
# First test
## SubHeader 1
kl;jdafkjjdsfajk;
![literally the most amazing apple ever](C:/Users/.../Stemilt-Cosmic-Crisp-Apple-2019.jpg)
This similar question 没有答案,但看起来需要“fig.cap”。我尝试将 {r fig.cap = "caption2- literally the most amazing apple ever"}
添加到代码中(如上面的第 5 行)但它不起作用,它只是打印了输入的确切文本,大括号等等。
答案 0 :(得分:2)
也许我想多了,但我在 HTML 输出文档中看到,您需要在 YAML 中使用 fig_caption: true
才能使图形带有标题。我使用了一些在 R 降价报告中发布图像时使用的包。
---
title: "test"
output:
html_document:
fig_caption: true
---
```{r setup, fig.cap="This is a screenshot",fig.align = 'center', warning=FALSE, message=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(cowplot)
library(magick)
ggdraw() +
draw_image("delete.png")
```
答案 1 :(得分:1)
您可以将 fig.cap
参数用于带有 knitr::include_graphics
的 R 代码块,或者通过降价图像链接提供标题。
一个最小的例子:
---
title: "Untitled"
output: html_document
---
# Option 1: `fig.cap` with `include_graphics`
```{r echo=FALSE, fig.cap = "Figure caption"}
knitr::include_graphics("https://mathworld.wolfram.com/images/gifs/rabbduck.jpg")
```
# Option 2: The markdown way way
![Figure caption](https://mathworld.wolfram.com/images/gifs/rabbduck.jpg)
生产