在 egg::ggarrange 中对齐多个绘图
Aligning multiple plot in egg::ggarrange
我正在用 egg::ggarrange 绘制 5 个数字的多图。我想知道如何在垂直位置对齐 b、d 和 c、e 的绘图区域?
PS:图b和c在y轴上的小数点必须不同。
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"
)
我正在用 egg::ggarrange 绘制 5 个数字的多图。我想知道如何在垂直位置对齐 b、d 和 c、e 的绘图区域?
PS:图b和c在y轴上的小数点必须不同。
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"
)