2013-06-09 13 views
12

geom_densityへのコールで制限の最後に行を削除するにはどうすればよいですか?ここでggplot2 geom_density limits

は一例です:

library(ggplot2) 
set.seed(1234) 

dfGamma = data.frame(nu75 = rgamma(100, 0.75), 
      nu1 = rgamma(100, 1), 
      nu2 = rgamma(100, 2)) 

dfGamma = stack(dfGamma) 
ggplot(dfGamma, aes(x = values)) + 
    geom_density(aes(group = ind, color = ind)) 

生成する、私はプロットの端に垂直青い線を取り除く、横1がXに沿って実行しているだろうか enter image description here

-軸?

答えて

14

geom_density()の代わりにstat_density()を使用し、引数をgeom="line"position="identity"と追加できます。

ggplot(dfGamma, aes(x = values)) + 
    stat_density(aes(group = ind, color = ind),position="identity",geom="line") 

enter image description here

+0

グレート、ありがとうございました。 – tchakravarty

2

同じ結果を生成するように思われる別の方法:

ggplot(dfGamma, aes(x = values, color=ind)) + geom_line(stat="density")