R 标签不适合直方图中的“我的箱子”中心

R 标签不适合直方图中的“我的箱子”中心,r,axis,bar-chart,axis-labels,bins,R,Axis,Bar Chart,Axis Labels,Bins,我遇到的问题,以适应在正确的位置下的直方图箱标签,你可以看到在图片。 我正在使用以下代码: ![# 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.

我遇到的问题,以适应在正确的位置下的直方图箱标签,你可以看到在图片。 我正在使用以下代码:

![# 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]
![#类别名称

my.names轴的
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)

bpbar不是按1:6绘制的。你可以从barplot函数推导出实际的中点。看看答案。也许这是一个更好的dup,因为它直接指的是
barplot
,而不是
hist
:。我没有关闭自己,只是为了万一有人知道更好的dup。