我已经绘制了一个分布图,希望能够给95%以上的区域着色。然而当我试图使用这里文档记录的不同技术:ggplot2 shade area under density curve by group时,由于我的数据集长度不同,它并没有起作用。
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
rnorm
从分布中随机采样,还是仅使用dnorm
绘制经验函数就足够了? - jdobres