I\'m having some trouble aligning axis labels across facets in ggplot. I\'m trying to left align all of the y-axis labels to make the text look more uniform, but the moment the
You can pad the labels out to the length of the longest string and then display them in a fixed-width font:
max_width = max(nchar(as.character(test$label)))
test$label_padded = sprintf(paste0("%-", max_width, "s"), test$label)
# (Ignore this if not on Windows)
windowsFonts(Consolas = "Consolas")
ggplot(test, aes(x = xdum, y = label_padded, label = data)) +
facet_grid(facett~., scales = "free", space = "free") +
geom_tile() +
theme(axis.ticks = element_blank(),
axis.text.y = element_text(hjust = 0, family = "Consolas"))