2012-08-16 108 views
2

我有點難以讓我的直方圖繪製正確數量的垃圾箱。我希望每個bin都是值1-5,5-10,10-15等,但是當我使用stat_bin時,它將恢復爲範圍/ 30默認值。stat_bin恢復爲默認

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. 

我在想這可能是一些愚蠢的語法的東西,我沒有很好地掌握,而我正在閱讀。 我希望有人可以告訴我爲什麼會發生這種情況。

+0

請不要在您的問題中添加答案。我將刪除您的答案並將其作爲答案發布。 – Andrie 2012-08-16 17:49:43

回答

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) 
+0

謝謝。我沒有足夠的代表來回答我自己的問題,直到8小時之後或什麼 – Stephopolis 2012-08-16 18:14:18

+0

@user如果您想在過期時間後發佈自己的答案,請告訴我,我將刪除此答案。 (只需在此答案中添加評論,我就會收到通知。) – Andrie 2012-08-16 18:15:54