Boxplot - how to rotate x-axis labels to 45°?

You have to pass the data to ggplot2. That is what is causing the error.
Here is an example of rotating the x axis text by 45 degrees. The text spacing is not quite right.

library(ggplot2)
disprt <- data.frame(group = rep(c("AAAAAAAA", "BBBBBBBBBB"), 50), distances = rnorm(100))
ggplot(disprt, aes(group, distances)) + geom_boxplot() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

Created on 2020-11-07 by the reprex package (v0.3.0)

1 Like