在R中以45度角插入标签?

时间:2017-11-14 03:58:12

标签: r

boxplot()命令中有没有办法以45度角旋转标签?

我意识到las = 2命令将它们旋转为垂直于x轴,但我希望它们能够在45度。

1 个答案:

答案 0 :(得分:4)

以下内容如何:

# 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。或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

相关问题