0

在此处输入图像描述正如您在图片中看到的那样,我在将标签放置在直方图箱下的正确位置时遇到了问题。我正在使用这段代码:

![# Category names
my.names <- c("test1", "test2", "test3", "test4", "test5", "test6")

# Example data
data <- c(191,33,12,254,22,74)

# Normalize the example data as a percentage of the total
data.norm <- data / sum(data)

# Use barplot to plot the results
barplot(data.norm, beside=TRUE, col=c("grey10","grey20","grey30","grey40","grey50","grey60"))
text(1:6, par("usr")[3], labels=my.names, srt=45, pos=2, xpd=TRUE,offset=0.01)][2]

请帮助问候

4

1 回答 1

1

x轴值不一定是整数值。该barplot函数返回x绘图期间使用的值。尝试

bp<-barplot(data.norm, beside=TRUE, col=c("grey10","grey20","grey30","grey40","grey50","grey60"))
text(bp, par("usr")[3], labels=my.names, srt=45, pos=2, xpd=TRUE,offset=0.01)

反而。

在此处输入图像描述

于 2014-09-03T15:41:16.510 回答