【问题标题】:Histogram function in R - breaks argument not workingR中的直方图函数-中断参数不起作用
【发布时间】:2016-07-08 04:43:04
【问题描述】:

我喜欢为每行创建带有已定义中断的直方图对象:

Hist <- list()
for (i in 1:10) { 
   Hist[[i]] <- hist(data[i,],breaks=25)
}

但是我对休息的要求与输出中的休息次数之间存在差异。 而且直方图中的中断次数也不同。

有什么原因吗?

【问题讨论】:

  • AFAIK breaks 只是一个提示,并不总是适用于历史。
  • @rbm: 好吧,但是解释器确实应该告诉用户“忽略用户指定的breaks=25,使用32...” 否则就太Douglas-Adams对于文字...

标签: r plot histogram


【解决方案1】:

要获得一致的breaks,请指定一个向量。如您所料,不是整数!

是的,这是有原因的;)来自直方图帮助页面:?hist

`breaks` can be one of:
  
  1. a vector giving the breakpoints between histogram cells,
  2. a function to compute the vector of breakpoints,
  3. a single number giving the number of cells for the histogram,
  4. a character string naming an algorithm to compute the number of cells (see ‘Details’),
  5. a function to compute the number of cells.

在案例 3、4、5 中,数字只是一个建议;断点将设置为漂亮的值。如果breaks 是一个函数,则将x 向量作为唯一参数提供给它。


注意我用粗体突出显示的部分。

【讨论】:

  • 非常感谢。首先我遇到了错误:“一些'x'不计算在内;也许'breaks'不跨越'x'的范围”,但我发现这里的默认值是直方图单元格是右闭(左开)间隔.现在它正在工作。
猜你喜欢
  • 2021-08-04
  • 2020-08-04
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2019-06-02
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
相关资源
最近更新 更多