R:在 ggplot2 包中使用 geom_histogram 时,bins 的带是什么?

R: what are the bands of the bins in when using a geom_histogram in package ggplot2?

我使用以下代码创建了一个直方图:

  p<-ggplot(df, aes(x=value)) +
    geom_histogram(color="black", fill="white", binwidth=5)
  
  p

我的数据范围在 0 到 17 之间。垃圾箱的波段是什么,例如0 部分是 0-4 吗?有没有办法改变乐队开始的地方?

您可以告诉 ggplot 您希望其中一个 bin 居中的位置。例如,如果您想要 0、5、10 等之间的 bin,您可以这样做:

ggplot(df, aes(x = value)) +
  geom_histogram(color = "black", fill = "white", binwidth = 5, center = 2.5) 


数据

set.seed(1)
df <- data.frame(value = rpois(25000, 7))