r - 如何在R中组合多个图?

标签 r ggplot2 plot ggpubr

我想按特定顺序排列情节。

library(ggpubr)
data("ToothGrowth")
data("mtcars")
mtcars$name <- rownames(mtcars)
mtcars$cyl <- as.factor(mtcars$cyl)

# create boxplot
bxp <- ggboxplot(ToothGrowth, x = "dose", y = "len", color = "dose", palette = "jco")
# create dotplot
dp <- ggdotplot(ToothGrowth, x = "dose", y = "len", color = "dose", palette = "jco", binwidth = 1)

# create scatterplot
sp = ggscatter(mtcars, x = "wt", y = "mpg", add = "reg.line", conf.int = TRUE, color = "cyl", palette = "jco", shape = "cyl")+
  stat_cor(aes(color = cyl), label.x = 3)
# arrange the plots
ggarrange(sp,                                                 # First row with scatter plot
          ggarrange(bxp, dp, ncol = 2, labels = c("B", "C")), # Second row with box and dot plots
          nrow = 2, 
          labels = "A")                                       # Labels of the scatter plot

以这种方式排列绘图给了我输出。

outputw

但是,我希望以另一种方式输出,例如散点图应该位于下 Pane 中,bx 和 bp 应该位于顶部 Pane 中。我试过了

ggarrange(bxp, dp, ggarrange(sp, labels = c("C"), nrow = 1),
         nrow = 2, ncol = 2, labels=c("A", "B"))

但它给了我如下:

output2

散点图未填充下 Pane 。它位于 Pane 的一角

最佳答案

试试这个。

ggarrange(ggarrange(bxp, dp, 
                    nrow = 1, ncol = 2, labels=c("A", "B")),
          ggarrange(sp, labels = c("C"), nrow = 1, ncol = 1),
          nrow = 2, ncol = 1)

enter image description here

关于r - 如何在R中组合多个图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77657900/

相关文章:

mysql - R - 在 R 中使用 VPN 连接到 MySQL

r - 如何将 cairo 设置为 R 中 x11() 的默认后端?

r - 带有 ggplot2 for R 的多色标题

python - 用 python 绘制随时间变化的球落位置图

r - 不重叠的抖动点

R grepl 检查字符串是否包含我们所有的单词

r - 如何在本地硬盘上将 Shiny 的 react 性数据框作为 csv 存储并附加新条目

r - 从 R 调用软件模块(Java、Perl 等)

R time_trans 与 POSIXct 类的对象一起使用

objective-c - 带有动画的ios简单条形图