在一页上使用par绘制多个绘图

问题描述 投票:0回答:1

我试图在基数R中使用par函数在一个页面上创建多个图。我正在使用库ggpubr中的ggscatter函数。我做了这样的事情,但它不起作用

library(ggpubr)
par(mfrow=c(2,2))
plot(ggscatter(df, x = "a1", y = "a2", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson",
               add.params = list(color = "blue")))
plot(ggscatter(df, x = "a1", y = "b1", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson",
               add.params = list(color = "blue")))

这应该在一页上绘制,第一行中有2个图形。但相反,它被绘制在不同的页面上。不知道这里可能出了什么问题

r par
1个回答
2
投票

par()不适用于ggplot。使用ggarange()。尝试:

p1 <- ggscatter(df, x = "a1", y = "a2", add = "reg.line",
         conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson",
         add.params = list(color = "blue"))
p2 <- ggscatter(df, x = "a1", y = "b1", add = "reg.line",
         conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson",
         add.params = list(color = "blue"))

ggarrange(p1, p2, ncol = 2, nrow = 2)

有关更多信息,请访问此链接:https://www.r-bloggers.com/ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page/

© www.soinside.com 2019 - 2024. All rights reserved.