Quantcast
Channel: Left-adjust (hjust = 0) vertical x axis labels on facets with free scale - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by dww for Left-adjust (hjust = 0) vertical x axis labels on facets with free scale

$
0
0

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)

enter image description here


Viewing all articles
Browse latest Browse all 5

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>