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

时间:2018-03-20 23:52:18

标签: r plot r-markdown figure

我有绘图功能,可以产生像glm这样的四个图。直方图,箱线图和两个散点图。但我不能将它们放在我的文档中的正确位置,以便我可以看到所有信息。我希望在1行中有2个图并且宽,所以我可以看到所有信息,如标题等。

发布我的剧情功能毫无意义,因为它是我创作的一个类。

我的输出看起来总是这样 enter image description here

我有以下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)
```

1 个答案:

答案 0 :(得分:0)

我没有复制你的问题。使用可重现的一组图:

---
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")
```

enter image description here

在我看来,设置figures文件夹的knitr搞砸了。