R

R:y軸上的geom_density值[重複]

  • September 13, 2015

為什麼 geom_density 在密度圖中向我顯示高於 1 的值?如何將其更改為分數?

在此處輸入圖像描述

我的代碼用來生成情節

ggplot(data = input2, aes(x = r.close)) +
 geom_density(aes(y = ..density.., fill = `Próba`), alpha = 0.3, stat = "density", position = "identity") +

 xlab("y") + ylab("density") +
 theme_bw() +
 theme(plot.title=element_text(size = rel(1.6), face = "bold"),
       legend.position = "bottom",
       legend.background = element_rect(colour = "gray"),
       legend.key = element_rect(fill = "gray90"),
       axis.title = element_text(face = "bold", size = 13)) 

或者您可以只使用提供的計算..scaled..stat_density

library(ggplot2)

set.seed(1)
vals1 <- rbeta(1000, 0.5, 0.1)
vals2 <- rbeta(1000, 0.25, 0.3)

gg <- ggplot(data.frame(x=c(vals1, vals2),
                       grp=c(rep("a", 1000), rep("b", 1000))))
gg <- gg + geom_density(aes(x=x, y=..scaled.., fill=grp), alpha=1/2)
gg <- gg + theme_bw()
gg

在此處輸入圖像描述

引用自:https://stats.stackexchange.com/questions/172311

comments powered by Disqus