The perils of aligning plots in ggplot

后端 未结 1 1332
广开言路
广开言路 2020-12-03 03:33

QUESTION

How do you combine separate plots (ggplot2), with different y-axis and different plot heights, yet retain alignment?

DETAI

相关标签:
1条回答
  • 2020-12-03 04:10

    In your gtable g, you can set the relative panel heights,

    require(gtable)
    g1<-ggplotGrob(top)
    g2<-ggplotGrob(bottom)
    g<-gtable:::rbind_gtable(g1, g2, "first")
    panels <- g$layout$t[grep("panel", g$layout$name)]
    g$heights[panels] <- unit(c(1,2), "null")
    
    grid.newpage()
    grid.draw(g)
    
    0 讨论(0)
提交回复
热议问题