在 R Base System 上并排绘图而不是面板绘图

Side by Side Plotting Instead of Panel Plotting on R Base System

抱歉,如果之前有人问过这个问题,但我找不到类似的问题 post。 我正在尝试在 R 的基本系统上创建面板图。但是 R Studio 并排显示我的绘图,而不是在面板上。所以我试图从互联网上复制一些代码,但它仍然并排显示图表。例如,这段代码必须创建一个面板图吗?

library(datasets)
par(mfrow = c(1, 3), mar = c(4, 4, 2, 1), oma = c(0, 0, 2, 0))
with(airquality, {
   plot(Wind, Ozone, main = "Ozone and Wind")
   plot(Solar.R, Ozone, main = "Ozone and Solar Radiation")
   plot(Temp, Ozone, main = "Ozone and Temperature")
   mtext("Ozone and Weather in New York City", outer = TRUE)
})

但是愚蠢的 R studio 正在并排创建情节。 这是一个截图:

如果我重新启动 R 会话可能没问题,但我不想丢失我加载的变量。对这个问题有什么猜测吗? 顺便说一句,我在同一会话中使用 lattice 和 ggplot2 创建了一些图(我不知道它们是否相互影响。)

如果您在控制台中 运行 您的代码,您将获得面板图。 运行 控制台中的这段代码:

library(datasets)
par(mfrow = c(1, 3), mar = c(4, 4, 2, 1), oma = c(0, 0, 2, 0))
with(airquality, {
  plot(Wind, Ozone, main = "Ozone and Wind")
  plot(Solar.R, Ozone, main = "Ozone and Solar Radiation")
  plot(Temp, Ozone, main = "Ozone and Temperature")
  mtext("Ozone and Weather in New York City", outer = TRUE)
})

输出:

如果你在 Rmarkdown 中 运行 这个,你也会得到一个面板图。这是代码:

output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(datasets)
par(mfrow = c(1, 3), mar = c(4, 4, 2, 1), oma = c(0, 0, 2, 0))
with(airquality, {
  plot(Wind, Ozone, main = "Ozone and Wind")
  plot(Solar.R, Ozone, main = "Ozone and Solar Radiation")
  plot(Temp, Ozone, main = "Ozone and Temperature")
  mtext("Ozone and Weather in New York City", outer = TRUE)
})
```

pdf 输出: