Force X axis text on for all facets of a facet_grid plot

前端 未结 2 643
闹比i
闹比i 2020-12-03 02:58

I have the same problem as this user: I\'d like to make a facet_grid plot with a discrete x-axis, and I\'d like to have the x-axis labels be written under each

相关标签:
2条回答
  • 2020-12-03 03:53

    Script can be much simpler by using cbind.gtable:

    library(gtable)
    g <- ggplotGrob(p)
    # locate the panels
    panels <- grep("panel", g$layout$name)
    top <- unique(g$layout$t[panels])
    
    # intersperse a copy of the bottom axes
    all <- gtable:::cbind.gtable(
        g[seq.int(min(top)), ], 
        g[max(top)+1,],
        g[seq(min(top)+1, nrow(g)),], 
        size = "first")
    grid.newpage()
    grid.draw(all)
    
    0 讨论(0)
  • 2020-12-03 03:59

    You can insert a copy of the axes inside the gtable,

    library(gtable)
    g <- ggplotGrob(p)
    # locate the panels
    panels <- grep("panel", g$layout$name)
    top <- unique(g$layout$t[panels])
    # intersperse a copy of the bottom axes
    all <- gtable:::rbind_gtable(gtable:::rbind_gtable(g[seq.int(min(top)), ], 
                                                       g[max(top)+1,], "first"), 
                                 g[seq(min(top)+1, nrow(g)),], "first")
    grid.newpage()
    grid.draw(all)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题