LoginSignup
3
3

More than 5 years have passed since last update.

確率密度関数の曲線の下は塗らずに線だけ描きたい

Posted at

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()

NG_example.png

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')

OK_example.png

参考資料

この記事はStackOverFlowの以下の質問の日本語訳です(一部省略および改変)。
http://stackoverflow.com/questions/17006956/ggplot2-geom-density-limits

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3