Good afternoon. Recently I've faced a problem of building a histogram in R. I type: SP500hist<-hist(SP500logreturns,col="lightblue",breaks = 140, border="white",main="", xlab="Time",xlim=c(-0.001,0.001))

Hereby I specify, that the number of breaks = 140
But when I type: SP500hist$breaks

I get 179 breaks instead of 140. How could it happen?

breaks one of:
a vector giving the breakpoints between histogram cells,
a function to compute the vector of breakpoints,
a single number giving the number of cells for the histogram,
a character string naming an algorithm to compute the number of cells (see ‘Details’),
a function to compute the number of cells.
In the last three cases the number is a suggestion only; as the
breakpoints will be set to pretty values, the number is limited to
1e6 (with a warning if it was larger). If breaks is a function, the
x vector is supplied to it as the only argument (and the number
of breaks is only limited by the amount of available memory).

So, the breaks argument is only a suggestion. If you require a precise number of breaks, you must pass in an exact vector of break point values of length number of breaks you want + 1.

set.seed(123)
x <- rnorm(1000)
n <- 5
h1 <- hist(x, breaks = n)