r - html Rmarkdown中上图的标题

标签 r r-markdown bookdown

在RMarkdown中编织为HTML时,是否可以将标题移到图形上方?似乎在PDF中是可能的,即when knitting to PDF,但我不知道如何将其复制为HTML。我正在使用bookdown对数字进行编号。

当我运行这样的东西时:

```{r fig.cap= "caption"}
df <- data.frame(letter = letters[1:5], value = 1)

ggplot(df, aes(as(factor(1), value, fill = letters))) +
  geom_bar(stat = "identity")

```

标题显示在图的底部,但我想将其显示在图的上方。

最佳答案

对于HTML输出,您可以设置块选项fig.topcaption = TRUE以将标题放在图形上方。下面是一个最小的示例(它适用于html_document bookdown 的HTML输出格式):

---
title: "Reprex"
output:
  html_document: null
  bookdown::html_document2: null
---

```{r, fig.cap='A caption.', fig.topcaption=TRUE}
plot(cars)
```

Caption above the figure

关于r - html Rmarkdown中上图的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56979022/

相关文章:

javascript - 用datatable()显示最后一页数据

r - 如何在维基百科页面上绘制扇形图

r - Knit 和父子 R 代码块 : A child's chunk can't recognize parent's variables within loop

r - 在 R bookdown 中如何设置默认代码输出背景颜色

r - bookdown::word_document2 中各部分的交叉引用不起作用

r - 使用 dong 在 R 中调试 foreach

algorithm - 如何在响应矩阵的每一列上计算最小但快速的线性回归?

r - R TinyTeX 安装会干扰我电脑上的其他 LaTeX 安装吗

html - 包括带有 knitr 的交互式 3D 人偶

r - LaTeX 表格中的链接文本与 knitr/kable