在egg::ggarrange中对齐多个绘图

在egg::ggarrange中对齐多个绘图,r,ggplot2,plot,egg,R,Ggplot2,Plot,Egg,我正在用egg::gg制作一个多点图,排列为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() #

我正在用egg::gg制作一个多点图,排列为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" 
      ) 
库(egg)
图书馆(GG2)
数据(“增长”)
数据(“mtcars”)

P1您可以使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)
图书馆(GG2)
图书馆(ggpubr)
数据(“增长”)
数据(“mtcars”)

亲爱的艾伦,非常感谢你。所列数字只是一个样本。在我的例子中,问题只是因为y轴上的小数点不同。如果必须是不同的十进制数,你有解决这个问题的办法吗?谢谢。@Jellz您可以将y轴上的数字旋转90度,或者将它们四舍五入到特定的小数位数?@Jeliz,或者将标签指定为字符串,并用空格填充短标签?@Jeliz或使用坐标_fixed@DearAllan,将标签指定为stings是一个非常好的主意。非常感谢你!!!