Shade density plot to the left of vline?

Viewed 597

Is it possible to shade a density plot using a vline as cutoff? For example:

df.plot <- data.frame(density=rnorm(100))
library(ggplot2)
ggplot(df.plot, aes(density)) + geom_density() + 
  geom_vline(xintercept = -0.25)

I tried creating a new variable, but it does not work as I expected

df.plot <- df.plot %>% mutate(color=ifelse(density<(-0.25),"red","NULL"))


ggplot(df.plot, aes(density, fill = color, colour = color)) + geom_density() + 
  geom_vline(xintercept = -0.25)
1 Answers
Related