我想按照特定的顺序安排情节。
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"))
但它给了我如下:
散点图未填充下窗格。它位于窗格的一角
尝试这个。