runiform-distribution

Create a uniform distribution in R and it's histogram is weird


enter image description here

c1<- seq(1,10,0.1)
hist(c1, breaks = 7, right = FALSE, ylim = c(1,10))

why is there always a part that is higher at the edge?


Solution

  • It's because there are 11 values in c1 that are between 9.0 and 10.0 (both inclusive). For each other bin, for example, [1, 2) there are only 10 values, as the upper edge belongs to the next bin. But for the last bin, the upper edge (10.0) is included.

    If you only run your sequence until 9.9, you get the desired histogram

    c1 <- seq(1, 9.9, 0.1)
    hist(c1, breaks = 7, right = FALSE, ylim = c(1,10))