且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 R 中为条形图旋转 x 轴标签

更新时间:2023-11-21 20:57:22

根据大卫的回答编辑答案:

EDITED ANSWER PER DAVID'S RESPONSE:

这是一种骇人听闻的方式.我猜有一种更简单的方法.但是您可以通过从 barplot 保存条形位置并上下稍微调整来抑制条形标签和标签的绘图文本.以下是 mtcars 数据集的示例:

Here's a kind of hackish way. I'm guessing there's an easier way. But you could suppress the bar labels and the plot text of the labels by saving the bar positions from barplot and do a little tweaking up and down. Here's an example with the mtcars data set:

x <- barplot(table(mtcars$cyl), xaxt="n")
labs <- paste(names(table(mtcars$cyl)), "cylinders")
text(cex=1, x=x-.25, y=-1.25, labs, xpd=TRUE, srt=45)