Reputation: 13
I have a return series, I have plotted the histogram but I need to add the density curve and 0.05 quantile line to this. How can I do this simply?
My histogram code:
ggplot(MyData, aes(x=Returns)) + geom_histogram(binwidth=1, colour="black", fill="white")
What I tried in order to add the quantile line:
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)
Upvotes: 1
Views: 6656
Reputation: 660
Try this:
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")
Hope it helps
Upvotes: 1