Чтобы настроить оси в базовом графике, вам нужно восстанавливать их по частям:
data('mpg', package = 'ggplot2')
x_labs <- levels(factor(mpg$class))
boxplot(hwy ~ class, mpg, main = "Highway MPG by car type",
xlab = NULL, ylab = "Highway MPG", col = "grey", xaxt = 'n') # don't plot axis
axis(1, labels = FALSE) # add tick marks
text(x = seq_along(x_labs), y = 9, labels = x_labs,
srt = 45, # rotate
adj = 1, # justify
xpd = TRUE) # plot in margin
mtext("Car Type", side = 1, padj = 6) # add axis label
Это немного проще в ggplot, так как он обрабатываетмного выравнивания, отслеживание меток и т. д. для вас:
library(ggplot2)
ggplot(mpg, aes(class, hwy)) +
geom_boxplot(fill = 'grey') +
labs(title = "Highway MPG by car type", x = "Car type", y = "Highway MPG") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))