R:直方图 bin 的控制数

R: Control number of histogram bins

我正在使用 hist 函数来分析我生成的一些数据。对于分析测定,我想精确控制直方图箱的数量。

我知道 "break-argument" 并且我可以看到在许多情况下,垃圾箱的数量与中断的数量直接相关(即 no_bins = no_breaks + 1 ).

由于 R 的算法,情况并非总是如此。有没有办法强制 R 输出特定数量的箱子?

如果我需要指定更多详细信息,请告诉我。

最好,非常感谢!

?hist 开始,有几个选项可以通过 breaks 参数控制 bin。

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.

为了获得最大的精度,您必须准确设置断点,方法是提供断点向量或计算断点的函数。您需要用断点覆盖 x 的整个范围,并且断点比垃圾箱多 1 个(即 no_bins + 1 = no_breaks)。