Histogram of uniform distribution not plotted correctly in R

前端 未结 3 1977
醉梦人生
醉梦人生 2020-12-20 22:55

When I run the code

hist(1:5)

or

hist(c(1,2,3,4,5))

The generated histogram shows that the first number \

3条回答
  •  无人及你
    2020-12-20 23:47

    Try this:

    > trace("hist.default", quote(print(fuzzybreaks)), at = 25)
    Tracing function "hist.default" in package "graphics"
    [1] "hist.default"
    >
    > out <- hist(1:5)
    Tracing hist.default(1:5) step 25 
    [1] 0.9999999 2.0000001 3.0000001 4.0000001 5.0000001
    > out$count
    [1] 2 1 1 1
    

    which shows the actual fuzzybreaks value it is using as well as the count in each bin. Clearly there are two points in the first bin (between 0.9999999 and 2.0000001) and one point in every other bin.

    Compare with:

    > out <- hist(1:5, breaks = 0:5 + 0.5)
    Tracing hist.default(1:5, breaks = 0:5 + 0.5) step 25 
    [1] 0.4999999 1.5000001 2.5000001 3.5000001 4.5000001 5.5000001
    > out$count
    [1] 1 1 1 1 1
    

    Now there is clearly one point in each bin.

提交回复
热议问题