如何删除直方图中 bin 之间的 space
How to remove space between bins in histogram
显然,如果绘制的向量的长度超过 2,000 个值,hist
将用空格分隔 bins:
par(mfrow=c(1,2))
hist(sample(1:10, 2000, replace = T), main = "", col = "grey")
hist(sample(1:10, 2100, replace = T), main = "", col = "grey")
如果绘制的矢量包含超过 2000 个值,空间怎么会是 removed/avoided?
不加空格;它增加了垃圾箱。保留 breaks = 9
并且它像以前一样工作:
par(mfrow=c(1,2))
hist(sample(1:10, 2000, replace = T), main = "", col = "grey")
hist(sample(1:10, 2100, replace = T), main = "", col = "grey", breaks = 9)
跳转的原因是 hist
计算中断的默认方法是 nclass.Sturges(x)
,其中 x
是您的矢量。这个简单的函数就是ceiling(log2(length(x)) + 1)
。在您的情况下,如果向量长于 2048,当计算的 bin 从 12 跳到 13 时,将发生转换:
hist(sample(1:10, 2048, replace = T), main = "", col = "grey")
hist(sample(1:10, 2049, replace = T), main = "", col = "grey")
由 reprex package (v0.3.0)
于 2020 年 7 月 20 日创建
显然,如果绘制的向量的长度超过 2,000 个值,hist
将用空格分隔 bins:
par(mfrow=c(1,2))
hist(sample(1:10, 2000, replace = T), main = "", col = "grey")
hist(sample(1:10, 2100, replace = T), main = "", col = "grey")
如果绘制的矢量包含超过 2000 个值,空间怎么会是 removed/avoided?
不加空格;它增加了垃圾箱。保留 breaks = 9
并且它像以前一样工作:
par(mfrow=c(1,2))
hist(sample(1:10, 2000, replace = T), main = "", col = "grey")
hist(sample(1:10, 2100, replace = T), main = "", col = "grey", breaks = 9)
跳转的原因是 hist
计算中断的默认方法是 nclass.Sturges(x)
,其中 x
是您的矢量。这个简单的函数就是ceiling(log2(length(x)) + 1)
。在您的情况下,如果向量长于 2048,当计算的 bin 从 12 跳到 13 时,将发生转换:
hist(sample(1:10, 2048, replace = T), main = "", col = "grey")
hist(sample(1:10, 2049, replace = T), main = "", col = "grey")
由 reprex package (v0.3.0)
于 2020 年 7 月 20 日创建