绘制在该R,可以绘制直方图和保存它的属性对变量:变量影响直方图HIST()函数中的R
> h1=hist(c(1,1,2,3,4,5,5), breaks=0.5:5.5)
这些属性可以接着读:
> h1
$breaks
[1] 0.5 1.5 2.5 3.5 4.5 5.5
$counts
[1] 2 1 1 1 2
$density
[1] 0.2857143 0.1428571 0.1428571 0.1428571 0.2857143
$mids
[1] 1 2 3 4 5
$xname
[1] "c(1, 1, 2, 3, 4, 5, 5)"
$equidist
[1] TRUE
attr(,"class")
[1] "histogram"
这些属性如何影响直方图?到目前为止,我已经计算出以下内容:
$breaks
和$counts
之间的关系。 $breaks
表示的时间间隔,其中标绘数据可以落入和$counts
表示落入这个间隔中的数据的量,例如:
[]表示closed interval(包括端点)
()表示open interval(端点不包括在内)
BREAKS : COUNTS
[0.5-1.5] : 2 # There are two 1 which falls into this interval
(1.5-2.5] : 1 # There is one 2 which falls into this interval
(2.5-3.5] : 1 # There is one 3 which falls into this interval
(3.5-4.5] : 1 # There is one 4 which falls into this interval
(4.5-5.5] : 2 # There are two 5 which falls into this interval
$breaks
和$density
之间的关系基本上是与上述相同,但写入百分比,例如:
BREAKS : DENSITY
[0.5-1.5] : 0.2857143 # This interval covers cca 28% of plot
(1.5-2.5] : 0.1428571 # This interval covers cca 14% of plot
(2.5-3.5] : 0.1428571 # This interval covers cca 14% of plot
(3.5-4.5] : 0.1428571 # This interval covers cca 14% of plot
(4.5-5.5] : 0.2857143 # This interval covers cca 28% of plot
当然,当你总结所有这些值,你将获得1:
> sum(h1$density)
[1] 1
继代表x轴的名字:
$xname
[1] "c(1, 1, 2, 3, 4, 5, 5)"
但到底是什么做的,其余做,尤其是$mids
?
$mids
[1] 1 2 3 4 5
$equidist
[1] TRUE
attr(,"class")
[1] "histogram"
另外,help(hist)
回报许多人一样,不应该他们也列在上面的输出,如果没有,为什么?正如在following文章
默认情况下解释,箱数包括值小于或等于斌的 右路突破点和严格比斌的左路突破 点时,除了最左边的垃圾桶,其中包括其左破 点。
所以以下:
h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=0.5:5.5)
将返回直方图,其中1.5将落入0.5-1.5区间。一种“解决方法”是将间隔尺寸设置为例如小于
h1=hist(c(1,1,2,3,4,5,5,1.5), breaks=seq(0.5,5.5,0.1))
但这似乎不现实的我,这也增加了$counts
和$density
一串0,有没有更好的,自动的方式?
除了这个,它也有一个副作用,我不能解释自己:为什么最后一个例子在总结10而不是1返回?
> sum(h1$density)
[1] 10
> h1$density[h1$density>0]
[1] 2.50 1.25 1.25 1.25 1.25 2.50
请阅读'?[functionname]'张贴这样的问题了。 –