R-Amateur
R-Amateur

Reputation: 13

Histogram, Density Plot, Quantile Line

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

Answers (1)

Athos
Athos

Reputation: 660

Try this:

Quantile line

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

Density

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

Hope it helps

Upvotes: 1

Related Questions