我已经绘制了一个分布,我想对> 95% 的区域进行着色。但是,当我尝试使用此处记录的不同技术时:ggplot2 按组密度曲线下的阴影区域它不起作用,因为我的数据集的长度不同。
AGG[,1]=seq(1:1000)
AGG[,2]=rnorm(1000,mean=150,sd=10)
Z<-data.frame(AGG)
library(ggplot2)
ggplot(Z,aes(x=Z[,2]))+stat_density(geom="line",colour="lightblue",size=1.1)+xlim(0,350)+ylim(0,0.05)+geom_vline(xintercept=quantile(Z[,2],prob=0.95),colour="red")+geom_text(aes(x=quantile(Z[,2],prob=0.95)),label="VaR 95%",y=0.0225, colour="red")
#I want to add a shaded area right of the VaR in this chart
Run Code Online (Sandbox Code Playgroud)