Q.
以下のコードで確率密度関数を描くと、枠線(図の赤い矢印のところ)がついて嫌なんです。消したいのですが、いい方法ありますか?
NG_example.R
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, group=ind, color=ind)) +
geom_density()
A.
ggplotのところを以下のように書くとよいでしょう。
OK_example1.R
ggplot(dfGamma, aes(x=values, group=ind, color=ind)) +
stat_density(position='identity', geom='line')
また、以下のように書くこともできます。
OK_example2.R
ggplot(dfGamma, aes(x=values, group=ind, color=ind)) +
geom_line(stat='density')
参考資料
この記事はStackOverFlowの以下の質問の日本語訳です(一部省略および改変)。
http://stackoverflow.com/questions/17006956/ggplot2-geom-density-limits