0

我创建了一个Rmarkdown文档并想给我的数字编号。我正在苦苦挣扎的是,如果 aplot给了我几个输出,比如plot("glm Object")

这是一个最小的例子:

---
documentclass: article
output: pdf_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(fig.path = 'figures/', fig.pos = 'htb!', echo = TRUE)
```

```{r, fig.cap = "Test"}
data(warpbreaks)
daten <- as.data.frame(warpbreaks)
test <- glm(breaks ~ tension + wool , family = "poisson", data = daten)
plot(test)
```
4

1 回答 1

0

您可以使用 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)
```

在此处输入图像描述

于 2018-03-20T08:31:42.070 回答