Выравнивание нескольких участков в яйце :: ggarrange - PullRequest
0 голосов
/ 04 февраля 2020

Я делаю мультиплот с 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" 
      ) 

enter image description here

1 Ответ

1 голос
/ 04 февраля 2020

Вы можете просто сделать шкалу 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" 
      ) 

enter image description here

...