简体   繁体   中英

Inserting labels in box plot in R on a 45 degree angle?

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.

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);

在此处输入图片说明


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));

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM