我创建了一个Rmarkdown
文档,想要对我的数字进行编号。我正在努力的是,plot
给了我几个输出,如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)
```
答案 0 :(得分: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)
```