gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:35:41 25 4
gpt4 key购买 nike

我有 plot 函数,可以像 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)
```

最佳答案

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

---
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

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

关于r - 在 RMarkdown 中的单个图形中绘制多个图的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49395974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com