Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 直接在ggplot中设置直方图的箱数_R_Ggplot2_Histogram - Fatal编程技术网

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

R 直接在ggplot中设置直方图的箱数,r,ggplot2,histogram,R,Ggplot2,Histogram,我想为我的直方图输入geom\u直方图箱子的数量,而不是通过binwidth控制箱子。说我可以通过设置bins参数来实现这一点。但是当我跑的时候 ggplot(data = iris, aes(x = Sepal.Length)) + stat_bin(bins = 5) 我得到一条包含30个箱子的输出消息,好像我根本没有指定binwidth stat_bin:bin宽度默认为范围/30。使用“binwidth=x”调整此值 我试着用同样的问题将这个参数输入到stat\u bin和qplot。

我想为我的直方图输入
geom\u直方图
箱子的数量,而不是通过
binwidth
控制箱子。说我可以通过设置
bins
参数来实现这一点。但是当我跑的时候

ggplot(data = iris, aes(x = Sepal.Length)) + stat_bin(bins = 5)
我得到一条包含30个箱子的输出消息,好像我根本没有指定binwidth

stat_bin:bin宽度默认为范围/30。使用“binwidth=x”调整此值

我试着用同样的问题将这个参数输入到
stat\u bin
qplot
。我做错什么了吗


我正在使用ggplot2 1.0.1版。

直接传递
bins=x

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

ggplot(df, aes(x=a)) + geom_histogram()
产生:


使用ggplot2 2.0.0版

您可以共享您的数据吗?您使用的是ggplot的哪个版本?如果您更新到ggplot2.0,stat_bin(bins=x)命令应该有效。对我有效。考虑更新GGPrand和/或重新启动R会话。它对我来说很好,但奇怪的是:它总是比我指定的多生成一个bin。索引0错误?(ggplot 2.0.0)给@bouncyball的帽子提示,很明显,在我写这篇文章的时候,你的评论也有同样的效果
ggplot(df, aes(x=a)) + geom_histogram(bins=10)