Histogram of uniform distribution not plotted correctly in R

前端 未结 3 1975
醉梦人生
醉梦人生 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:25

    Taking your first example, hist(1:5), you have five numbers, which get put into four bins. So two of those five get lumped into one.

    The histogram has breaks at 2, 3, 4, and 5, so you can reasonably infer that the definition of hist for where a number is plotted, is:

    #pseudocode
    if (i <= break) { # plot in bin }
    

    You can specify the breaks manually to solve this:

    hist(1:5, breaks=0:5)
    

    enter image description here

提交回复
热议问题