I am using the hist-function to analyze some data I generated. For an analysis-assay I would like to precisely control the number of histogram bins.
I know the \"break-a
From ?hist
, there are several options for controlling the bins through the breaks
argument.
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; the breakpoints will be set to pretty values. If breaks is a function, the x vector is supplied to it as the only argument.
For the greatest precision, you have to set the breakpoints exactly, either by supplying a vector of breakpoints, or a function to compute them. You need to cover the entire range of x with your breakpoints and there will be 1 more breakpoint than bins (i.e. no_bins + 1 = no_breaks).