【问题标题】:R : Histogram adjust frequency scale representationR:直方图调整频率尺度表示
【发布时间】:2015-07-18 21:45:36
【问题描述】:

这可能是一件非常微不足道的事情,但由于我在 R 方面没有太多经验,所以我可能会遗漏一些东西。基本上,我的频率值很大,用 y 轴上的指数表示-

这里是计数

# $counts
#  [1] 374850  81009  56419  45259  35765  29697  25637  23587  21461  19418  18221  17094  15902  15098  13874  13257
# [17]  12602  11883  10974  10427   9553   9213   8278   7975   7325   6904   6641   5989   5467   4684   4253   3704
# [33]   3355   2918   2722   2427   2301   2178   1909   1786   1657   1462   1346   1178   1061    900    745    651
# [49]    437    316    214     63

我明白,这是一个相当广泛的范围。有没有一种方法可以压缩比例并且仍然具有有意义的值,例如 K(千)或 M(百万)?

【问题讨论】:

  • 您要禁用科学记数法吗?

标签: r scale histogram frequency


【解决方案1】:

您可以先在 hist 调用中禁用轴,然后在 axTicks 的帮助下再次添加轴。

# generate some data
x <- rchisq(1000000,df=1)

# create histogram
x.hist <- hist(x,breaks=7,axes=FALSE)

# create new axis

# draw axis along 'y' axTicks(2) gets the values along 'x' from your plot
axis(2, at=axTicks(2), labels=paste(axTicks(2)/1000000,"mil",sep=""))

# draw axis along 'x' axTicks(1) gets the values along 'x' from your plot
axis(1, at=axTicks(1), labels=paste( axTicks(1) ," hats",sep=""))

你得到的东西看起来像这样,

【讨论】:

  • 这很好用乔纳森。谢谢!附带说明 - 如果您在我的帖子中注意到,y 轴没有涵盖最大频率,您能否评论一下为什么会发生这种情况?
  • 如果你在 hist 中设置 ylim 你可以设置频率的最大值。例如hist(x,axes=FALSE,ylim=(0,200000))
  • 谢谢。我现在明白了很多。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-08
  • 2018-06-08
  • 2012-09-21
  • 2020-01-27
相关资源
最近更新 更多