We can edit the text grobs after generating the plot, using library(grid)
.
g <- ggplot(data = diamonds, aes(cut_label, carat)) + facet_grid(~cut, scales = "free_x") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5))gt <- cowplot::as_gtable(g)axis_grobs <- which(grepl("axis-b", gt$layout$name))labs <- levels(factor(diamonds$cut_label))[order(levels(diamonds$cut))]for (i in seq_along(axis_grobs)) { gt$grobs[axis_grobs[i]][[1]] <- textGrob(labs[i], y = unit(0, "npc"), just = "left", rot = 90, gp = gpar(fontsize = 9))}grid.draw(gt)