I want to add background colour to the different quantiles in a plot. Below I have the start. But not sure how to:
- Keep the values of the x-axes (i.e., now it is the percentages, but I want the scores)
- Control the colours
- Set the transparency of the colour
dt <- data.frame(scores=rnorm(200))
dens <- density(dt$scores)
df <- data.frame(x=dens$x, y=dens$y)
quantiles <- quantile(dt$scores, prob=c(0.25, 0.5, 0.75))
df$quantile <- factor(findInterval(df$x, quantiles))
levels(df$quantile) <- c("<25%", "25%-50%", "50-75%", "75-100%")
ggplot(df, aes(x, y)) +
geom_line() +
geom_ribbon(aes(ymin=0, ymax=y, fill=quantile)) +
scale_x_continuous(breaks=quantiles)

