R:控制直方图箱数 [英] R: Control number of histogram bins
问题描述
我正在使用历史函数分析我生成的一些数据.对于分析测定,我想精确控制直方图箱的数量.
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.
我知道中断参数",并且我可以看到在许多情况下垃圾箱的数量与中断的数量成正比(即no_bins = no_breaks + 1).
I know the "break-argument" and I can see that in many cases the number of bins is in a direct relationship to the number of breaks (i.e. no_bins = no_breaks + 1).
由于R的算法并非总是如此.有没有办法强迫R输出特定数量的垃圾箱?
Due to R's algorithm this is not always the case. Is there a way to force R to output a specific number of bins?
让我知道是否需要指定更多详细信息.
Let me know if I need to specify further details.
非常感谢!
推荐答案
在?hist
中,有几个选项可通过breaks
参数控制垃圾箱.
From ?hist
, there are several options for controlling the bins through the breaks
argument.
breaks
之一:
给出直方图单元格之间断点的向量
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.
在最后三种情况下,该数字仅是建议值;这 断点将被设置为漂亮的值.如果中断是一个功能,则 x向量是唯一的参数.
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的整个范围,断点比bin还要多1个(即no_bins +1 = no_breaks).
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).
这篇关于R:控制直方图箱数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!