Left align two graph edges (ggplot)

前端 未结 9 1289
梦谈多话
梦谈多话 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

    On http://rpubs.com/MarkusLoew/13295 is a really easy solution available (last item) Applied to this problem:

    require(ggplot2);require(gridExtra)
    A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +coord_flip() 
    B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip() 
    grid.draw(rbind(ggplotGrob(A), ggplotGrob(B), size="first"))
    

    you can also use this for both width and height:

    require(ggplot2);require(gridExtra)
    A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +coord_flip() 
    B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip() 
    C <- ggplot(CO2, aes(x=conc)) + geom_bar() +coord_flip()
    D <- ggplot(CO2, aes(x=uptake)) + geom_bar() +coord_flip() 
    grid.draw(cbind(
                rbind(ggplotGrob(A), ggplotGrob(B), size="first"),
                rbind(ggplotGrob(C), ggplotGrob(D), size="first"),
                size='first'))
    

提交回复
热议问题