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
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)
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)