在 RMarkdown 中的单个图形中绘制多个图的问题

Issues plotting multiple plots in a single figure within RMarkdown

我有像 glm 一样生成四个图的绘图函数。直方图、箱线图和两个散点图。但我无法将它们放在我文档中的正确位置,以便我可以看到所有信息。我想要 1 行中的 2 个地块并且要宽,以便我可以看到所有信息,例如 header 等

我的绘图函数 post 毫无意义,因为它是我创建的 class。

我的输出总是这样

我有以下 YAML 布局:

---
title: 
author:
fontsize: 11
graphics: true
documentclass: article
output: 
  pdf_document:
    fig_caption: yes
    toc: true
    latex_engine: pdflatex
    toc_depth: 2
    number_sections: true
    keep_tex: true
header-includes: 
- \usepackage{graphicx}
- \usepackage{float}
- \usepackage{subfig}
---

```{r setup, include = FALSE}
library(knitr)
knitr::opts_chunk$set(fig.path = 'figures/', fig.pos = 'htb!', echo = TRUE)
knit_hooks$set(plot = function(x, options)  {
  hook_plot_tex(x, options)
})
```

```{r, out.width='1\linewidth', fig.asp=0.5, fig.ncol = 1, fig.cap="output",fig.align = "center"}
par(mfrow = c(1, 2))
plot(poisReg)
```

我无法复制您的问题。使用一组可重现的图:

---
title: 
author:
fontsize: 11
graphics: true
documentclass: article
output: 
  pdf_document:
    fig_caption: yes
    toc: true
    latex_engine: pdflatex
    toc_depth: 2
    number_sections: true
    keep_tex: true
header-includes: 
- \usepackage{graphicx}
- \usepackage{float}
- \usepackage{subfig}
---

```{r setup, include = FALSE}
library(knitr)
knitr::opts_chunk$set(fig.path = 'figures/', fig.pos = 'htb!', echo = TRUE)
knit_hooks$set(plot = function(x, options)  {
  hook_plot_tex(x, options)
})
```

```{r, out.width='1\linewidth', fig.asp=0.5, fig.ncol = 1, fig.cap="output",fig.align = "center"}
par(mfrow = c(1, 2))
plot(cars, main = "Title 1")
plot(cars, main = "Title 2")
plot(cars, main = "Title 3")
plot(cars, main = "Title 4")
```

在我看来,knitr 设置 figures 文件夹时出现问题。