2011-11-08 24 views
4

I'am。ggplotのbinwidthを変更する方法は? ggplotでヒストグラムをやって

p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) + 
    xlab(xlabel) + ylab(ylabel) + 
    geom_histogram(colour = "darkblue", fill = "white", binwidth=500) 

私のxは2から6580の間で、私は2600のデータを持っています。

私は別のbinwidthで1つのヒストグラムをプロットしたいです。出来ますか?

例えば、私はこのような幅の8つの小節を持つようにしたい:

c(180,100,110,160,200,250,1000,3000) 

私はそれをどのように行うことができますか?

答えて

15

どのようにブレークを使用してはどうですか?

x <- rnorm(100) 
ggplot(NULL, aes(x)) + 
    geom_histogram(breaks = c(-5, -2, 0, 5), 
    position = "identity", colour = "black", fill = "white") 

P.S.明示的な通知なしに投稿を交差しないでください。

enter image description here

2

使用breaksposition="dodge"

例:

ggplot(mtcars,aes(x=hp))+geom_histogram(breaks=c(50,100,200,350),position="dodge") 

があなたのデータを持っていませんが、ご例えば:

p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) + 
    xlab(xlabel) + ylab(ylabel) + 
    geom_histogram(colour = "darkblue", fill = "white", breaks=cumsum(c(180,100,110,160,200,250,1000,3000)), position="dodge") 
+0

は、非常にそれをいただき、ありがとうございますは働いている – Tali

関連する問題