在RMarkdown中在单个图形中绘制多个图的问题 [英] Issues plotting multiple plots in a single figure within RMarkdown
问题描述
我有出图函数,可以生成四个像glm的图.直方图,箱线图和两个散点图.但是我不能将它们放在文档中的正确位置,这样我才能看到所有信息.我想要1行中有2个图并且要宽一些,这样我就可以看到所有信息,例如标题等.
I have plot function that produce four plots like glm. A histogramm, a boxplot and two scatterplots. But I cant put them in the right place in my document so that I can see all informations. I want 2 plots in 1 row and to be wide so I can see all informations like header etc.
发布我的plot函数是没有意义的,因为它是针对我创建的类的.
It's senseless to post my plot function, because it's for a class that I created.
我的输出看起来总是这样
My output looks always like this
我具有以下YAML布局:
I have the following YAML layout:
---
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)
```
推荐答案
我无法复制您的问题.使用一组可重复的图:
I am failing to replicate your problem. Using a reproducible set of plots:
---
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")
```
在我看来,设置figures
文件夹的编织器有些混乱.
It seems to me that something is being messed up the knitr setting up the figures
folder.
这篇关于在RMarkdown中在单个图形中绘制多个图的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!