您可以使用 Rmarkdown 鲜为人知的功能并为子图添加标题:https ://stackoverflow.com/a/49086985/7347699
对于您的示例:
---
documentclass: article
output: pdf_document
header-includes:
- \usepackage{subfig}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(fig.path = 'figures/', fig.pos = 'htb!', echo = TRUE)
```
```{r, fig.cap = "Test", fig.subcap=c('sub 1', 'sub 2', 'sub 3', 'sub 4'), out.width='.49\\linewidth', fig.asp=1, fig.ncol = 2}
data(warpbreaks)
daten <- as.data.frame(warpbreaks)
test <- glm(breaks ~ tension + wool , family = "poisson", data = daten)
plot(test)
```
替代方法
绘制多个 R 图的一种可能更简单的方法是par
在绘制之前使用该函数。这样做的好处是它的简单性,并且您不需要在标头中加载其他 LaTeX 包。但是,不可能为每个图添加子标题。
---
documentclass: article
output: pdf_document
---
```{r, fig.cap = "Test", fig.asp = 1}
data(warpbreaks)
daten <- as.data.frame(warpbreaks)
test <- glm(breaks ~ tension + wool , family = "poisson", data = daten)
par(mfrow = c(2, 2))
plot(test)
```