【问题标题】:Labels do not fit to my bin center in histogram标签不适合我在直方图中的 bin 中心
【发布时间】:2014-09-03 15:33:20
【问题描述】:

我在将标签放置在直方图箱下的正确位置时遇到问题,如图所示。 我正在使用此代码:

![# 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]

请帮忙 问候

【问题讨论】:

  • 条形图不是以 1:6 绘制的。您可以从 barplot 函数得出实际的中点。看看this的答案。
  • 也许这是一个更好的 dup,因为它直接引用 barplot 而不是 hist: stackoverflow.com/questions/18634431/…。我没有关闭自己,以防有人知道更好的副本。

标签: r axis bar-chart axis-labels bins


【解决方案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)

改为。

【讨论】:

    猜你喜欢
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多