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 tjebo for Left-adjust (hjust = 0) vertical x axis labels on facets with free scale

$
0
0

One way, and possibly the most straight forward hack, would be to annotate outside the coordinates.

Disadvantage is that the parameters would need manual adjustments (y coordinate, and plot margin), and I don't see how to automate this.

library(ggplot2)diamonds$cut_label <- paste("Super Dee-Duper", as.character(diamonds$cut))ann_x <- data.frame(x = unique(diamonds$cut_label), y = -16, cut = unique(diamonds$cut))ggplot(data = diamonds, aes(cut_label, carat)) +  facet_grid(~cut, scales = "free_x") +  geom_text(data = ann_x, aes(x, y, label = x), angle = 90, hjust = 0) +  theme(    axis.text.x = element_blank(),    plot.margin = margin(t = 0.1, r = 0.1, b = 2.2, l = 0.1, unit = "in")  ) +  coord_cartesian(ylim = c(0, 14), clip = "off")

Created on 2020-03-14 by the reprex package (v0.3.0)


Viewing all articles
Browse latest Browse all 5

Trending Articles