我正在用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"
)
亲爱的艾伦,非常感谢。所列数字仅为示例。就我而言,问题仅在于y轴上的小数点不同。如果必须使用不同的十进制数,那么您对此问题有解决方案吗?谢谢。
@Jellz您可以将y轴上的数字旋转90度,或者将它们四舍五入到特定的小数位数?
@Jeliz还是将标签指定为字符串,并用空格填充简短的标签?
@Jeliz或使用coord_fixed
@亲爱的艾伦,将标签指定为ing是一个非常好的主意。非常感谢你!!!