Arrange ggplot plots (grobs with same widths) using gtable to create 2x2 layout

前端 未结 3 640
难免孤独
难免孤独 2021-02-01 11:14

I am attempting to use grobs and gtable to arrange 4 (ggplot2) plots into a 2x2 grid. I don\'t know how to set widths, and also a non- 1xn, or nx1 arrangement.

Using thi

3条回答
  •  孤街浪徒
    2021-02-01 11:36

    would this work for you

    library(cowplot)
    library(ggplot2)
    data(iris)
    a <- ggplot(iris, aes(x=Species, y=Petal.Width)) + geom_boxplot(color="black") + ylab(expression(Foo~Bar~(g~cm^{-3}))) + theme_grey()
    b <- ggplot(iris, aes(x=Species, y=Petal.Length*100)) + geom_boxplot(color="black") + ylab("foobar (mm)") + theme_grey()
    c <- ggplot(iris, aes(x=Species, y=Sepal.Width)) + geom_boxplot(color="black") + ylab("foobar (%)") + theme_grey()
    d <- ggplot(iris, aes(x=Species, y=log10(Sepal.Length))) + geom_boxplot(color="black") + ylab("foobar (cm)") + theme_grey()
    plot_grid(a,b, c, d, ncol=2,align="v")
    

提交回复
热议问题