Display y-axis for each subplot when faceting

后端 未结 1 2018
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 03:36

I am plotting three plots next to each other using facet_grid.

Facet grid will only draw the y-axis for the first plot. Is there a way to draw the y-axis for all thr

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

    You can copy the (part of the) y-axis and place copies for each panel,

    g <- ggplotGrob(plot1)
    
    require(gtable)
    axis <- gtable_filter(g, "axis-l")[["grobs"]][[1]][["children"]][["axis"]][,2]
    segment <- segmentsGrob(1,0,1,1)
    panels <- subset(g$layout, name == "panel")
    g <- gtable_add_grob(g, grobs=list(axis, axis), name="ticks",
                         t = unique(panels$t), l=tail(panels$l, -1)-1)
    
    g <- gtable_add_grob(g, grobs=list(segmentsGrob(1,0,1,1), 
                                       segmentsGrob(1,0,1,1)), 
                         t = unique(panels$t), l=tail(panels$l, -1)-1, 
                         name="segments")
    grid.newpage()
    grid.draw(g)
    
    0 讨论(0)
提交回复
热议问题