我正在用egg :: ggarrange绘制5个数字的多图。我想知道如何在垂直位置对齐b,d和c,e的绘图区域?
library(egg)
library(ggplot2)
data("ToothGrowth")
data("mtcars")
P1 <- ggplot(mtcars, aes(x = wt, y = mpg, color=cyl))+
geom_point() # Add correlation coefficient
P2 <- ggboxplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco")+
scale_y_continuous(breaks=c(10.5, 20.5, 30.5))
P3 <- ggdotplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco", binwidth = 1)
ggarrange(P1,
ggarrange(P2, P2, ncol = 2, labels = c("b", "d"), align = "h",widths = c(1.5,2)),
ggarrange(P3, P3, ncol = 2, labels = c("c", "e"), align = "h",widths = c(1.5,2)),
nrow = 3,
heights = c(1.5, 1, 1),
labels = "a"
)
您可以使y刻度相等,或者至少具有相同的小数位数:
library(egg)
library(ggplot2)
library(ggpubr)
data("ToothGrowth")
data("mtcars")
P1 <- ggplot(mtcars, aes(x = wt, y = mpg, color=cyl))+
geom_point() # Add correlation coefficient
P2 <- ggboxplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco")+
scale_y_continuous(breaks=c(10.5, 20.5, 30.5))
P3 <- ggdotplot(ToothGrowth, x = "dose", y = "len",
color = "dose", palette = "jco", binwidth = 1) +
scale_y_continuous(breaks=c(10.5, 20.5, 30.5))
ggarrange(P1,
ggarrange(P2, P2, ncol = 2, labels = c("b", "d"), align = "h",widths = c(1.5,2)),
ggarrange(P3, P3, ncol = 2, labels = c("c", "e"), align = "h",widths = c(1.5,2)),
nrow = 3,
heights = c(1.5, 1, 1),
labels = "a"
)