R:切断对于y轴太长的条

时间:2016-01-20 15:54:22

标签: r histogram

我在R中使用以下方式制作直方图:

hist(SOME_MATRIX[,4],breaks=500,ylim = c(0,1000))

但我的酒吧比我给y轴(0-1000)的范围高得多。有没有办法使用“hist()”来切断最大值的条形?

1 个答案:

答案 0 :(得分:2)

根据评论中讨论的警告,这里是如何在1000处切断栏:

# Save plot data in an object
x=hist(rnorm(1e5),breaks=50,ylim = c(0,1000))

# Cut off counts at 1000
x$counts[x$counts>1000] = 1000

# Re-plot histogram. Max of y-range is > 1000 to show cutoff.
plot(x, ylim=c(0,1500))

enter image description here