stat_bin恢复为默认值

时间:2012-08-16 17:36:42

标签: r ggplot2 histogram

我有点难以让我的直方图绘制正确的箱数。我希望每个bin都是值1-5,5-10,10-15等,但是当我使用stat_bin时它恢复到范围/ 30默认值。

ggplot(tmp,aes(x = values)) + 
+     facet_wrap(~ind) +
+     geom_histogram(aes(y=..count../sum(..count..)),stat="bin")+
+     scale_x_continuous("Percent above 30x")+
+     scale_y_continuous("Fraction of panel")+
+     opts(title = yz)+
+     stat_bin(bandwidth=5.0)
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.

我在想,这可能是一些愚蠢的语法,我在阅读时并没有完全掌握。 我希望有人可以告诉我为什么会这样。

1 个答案:

答案 0 :(得分:1)

OP发布了此解决方案:将binwidth=5参数添加到geom

ggplot(tmp,aes(x = values)) +
    facet_wrap(~ind) +
    geom_histogram(aes(y=..count../sum(..count..)), binwidth=5)+
    scale_x_continuous("Percent above 30x")+
    scale_y_continuous("Fraction of panel")+
    opts(title = yz)
相关问题