如何在R中合并多个地块?

92dk7w1h  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(124)

我想把情节按一定的顺序排列。

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

字符串
以这种方式安排这些图就可以得到输出。


的数据
但是,我希望以另一种方式输出,例如散点图应该在下窗格中,而bx和bp应该在上窗格中。

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


但它给了我如下:



散点图没有用下窗格填充。它在窗格的一个角落里

gr8qqesn

gr8qqesn1#

试试这个.

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)

字符串


的数据

相关问题