直接在ggplot中设置直方图的箱数

Emp*_*cer 12 r histogram ggplot2

我想geom_histogram为直方图提供垃圾箱的数量,而不是通过控制垃圾箱binwidth.文档说我可以通过设置bins参数来做到这一点.但是当我跑步的时候

ggplot(data = iris, aes(x = Sepal.Length)) + stat_bin(bins = 5)
Run Code Online (Sandbox Code Playgroud)

我得到一个带有30个bin的输出消息,好像我根本没有指定binwidth.

stat_bin:binwidth默认为范围/ 30.使用'binwidth = x'来调整它.

我已经试过这种说法喂养stat_binqplot同样的问题.难道我做错了什么?

我正在使用ggplot2版本1.0.1.

arv*_*000 22

bins=x直接通过

library(ggplot2)
df <- data.frame(a = rnorm(10000))

ggplot(df, aes(x=a)) + geom_histogram()
Run Code Online (Sandbox Code Playgroud)

产生这个(警告" stat_bin()使用bins = 30.选择更好的价值binwidth."):

在此输入图像描述

还有这个:

ggplot(df, aes(x=a)) + geom_histogram(bins=10)
Run Code Online (Sandbox Code Playgroud)

生产:

在此输入图像描述

使用ggplot2版本2.0.0