Left align two graph edges (ggplot)

前端 未结 9 1305
梦谈多话
梦谈多话 2020-11-22 01:08

I\'m using ggplot and have two graphs that I want to display on top of each other. I used grid.arrange from gridExtra to stack them. The problem is I want the

9条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 01:31

    The egg package wraps ggplot objects into a standardised 3x3 gtable, enabling the alignment of plot panels between arbitrary ggplots, including facetted ones.

    library(egg) # devtools::install_github('baptiste/egg')
    library(ggplot2)
    
    p1 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) +
      geom_point() 
    
    p2 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) +
      geom_point() + facet_wrap( ~ cyl, ncol=2, scales = "free") +
      guides(colour="none") +
      theme()
    
    ggarrange(p1, p2)
    

提交回复
热议问题