The code below fills each of the two densities with color under the area of the curve:
library(ggplot2)
#fake data
dat <- data.frame(dens = c(rnorm(100), rnorm(100, 2, 0.5))
, group = rep(c("C", "P"), each = 100))
#fill the area under the curve
ggplot(dat, aes(x = dens, fill = group)) + geom_density(alpha = 0.75)
How can I achieve the following two goals?
1) Only fill each curve within a specified interval. For example, interval [-1.5, 2.0] for group 'C' and [0.5, 2.8] for group 'P'.
2) Add a vertical segment (from x-axis to the curve) for each density. For example, at x=0.2 for group 'C' and at x=1.9 for group 'P'.