【发布时间】:2017-02-16 05:01:27
【问题描述】:
我遇到了以下场景...
以下代码生成 2 个相同的直方图:
library(ggplot2)
data("diamonds")
ggplot(diamonds, aes(x=price)) + geom_histogram(binwidth=1000)
qplot(price, data = diamonds, binwidth = 1000)
但是,我不明白他们如何推导出左边的第一个条形图/bin,事实上,整个直方图对我来说似乎是错误的。
另一方面:
hist(diamonds$price,breaks = seq(0,20000, by=1000))
为了验证我运行此代码的数据:
br = seq(0,20000,by=1000)
ranges = paste(head(br,-1), br[-1], sep=" - ")
freq = hist(diamonds$price, breaks = br, include.lowest=TRUE, plot=FALSE)
data.frame(range = ranges, frequency = freq$counts)
它会产生:
range frequency
1 0 - 1000 14524
2 1000 - 2000 9683
3 2000 - 3000 6129
4 3000 - 4000 4225
5 4000 - 5000 4665
...
那么ggplot 或qplot 中的第一个bar/bin 来自哪里?
【问题讨论】: