簡體   English   中英

直方圖,密度圖,分位數線

[英]Histogram, Density Plot, Quantile Line

我有一個返回序列,已經繪制了直方圖,但是我需要為此添加密度曲線和0.05分位數線。 我該如何簡單地做到這一點?

我的直方圖代碼:

ggplot(MyData, aes(x=Returns)) + geom_histogram(binwidth=1, colour="black", fill="white")

為了添加分位數線我嘗試了什么:

quantile <- quantile(Returns, prob = 0.05)

ggplot(MyData, aes(x=Returns)) + geom_histogram(binwidth=1, colour="black", fill="white") + 
  geom_vline(aes(xintercept=quantile), color="red", linetype="dashed", size=1)

嘗試這個:

分位數線

geom_vline(xintercept=quantile, color="red", linetype="dashed", size=1)

密度

geom_histogram(aes(y=..density..), binwidth=1, colour="black", fill="white") + geom_density(fill=NA, colour="royalblue")

希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM