0

Is there any way in the boxplot() command to rotate the labels at a 45-degree angle?

I realize the las=2 command rotates them to be perpendicular to the x axis, but I was hoping to have them at 45 degrees.

Boris Kris
  • 471
  • 1
  • 6
  • 6

1 Answers1

4

How about the following:

# Some sample data
x <- list(x = rnorm(100, 2), y = rnorm(100, 4));
# Plot without x axis
boxplot(x, xaxt = "n");
# Add axis labels rotated by 45 degrees
text(seq_along(x), par("usr")[3] - 0.5, labels = names(x), srt = 45, adj = 1, xpd = TRUE);

enter image description here


PS. Or easier/cleaner in ggplot:

require(ggplot2);
require(reshape2);
df <- melt(x);
ggplot(df, aes(L1, value)) + geom_boxplot() + theme(axis.text.x = element_text(angle = 45, hjust = 1));

enter image description here

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68