从离散值绘制直方图时如何分离箱

时间:2015-11-11 00:37:10

标签: r

我使用以下代码绘制离散值的直方图:

vect=c(1,1,2,3,4,5,5,1)
h1=hist(vect, breaks=1:max(vect), right=FALSE)

以下内容如下:

enter image description here

我的目标是按照post跟随分箱。我还试图应用上述帖子中的代码:

vect=c(1,1,2,3,4,5,5,1)
h1=hist(vect, breaks=1:rep(vect,each=2)+c(-.4,.4), right=FALSE)

但它会出错。第二次尝试遵循@TheTime建议的代码:

vect=c(1,1,2,3,4,5,5,1)
h1=hist(vect, breaks=rep(1:max(vect),each=2)+c(-.4,.4), right=FALSE)

这返回: enter image description here

正如你所看到的,有一些奇怪的数字1的值为1.6,2的值为1.4等。

> h1$breaks
 [1] 0.6 1.4 1.6 2.4 2.6 3.4 3.6 4.4 4.6 5.4

我做错了什么?

0 个答案:

没有答案