0

I'm looking for a way to fill in the area under a density plot, but only for part of the distribution. For example, consider the following distribution:

library("ggplot2")
set.seed(1234)
k <- rnorm(5000, mean=.1, sd=.08)
l <- data.frame(k)
avgk = mean(k)
ggplot(l, aes(x=k)) + geom_density(alpha = .5) + geom_vline(x=avgk) + geom_vline(x=0)

This creates a density curve with lines at 0 and the average. However, let's say I want to highlight the outcomes that are less than 0. (In this case, these are ROI percentages, and we want to look at the probability that it will be a money loser).

I would like to fill in the area under the curve that is 0 or less with a color.

plannapus
  • 18,529
  • 4
  • 72
  • 94
user3641120
  • 75
  • 1
  • 4
  • Also somewhat related is [this](http://stackoverflow.com/q/20355849/324364) question. – joran May 15 '14 at 14:16
  • Thank you for the quick answer. I looked for a dupe but couldn't stumble across the right keyword (I was looking for 'fill' rather than 'shade') – user3641120 May 15 '14 at 14:20
  • You spend enough time on StackOverflow and you start to remember specific questions without having to search at all. ;) – joran May 15 '14 at 14:44

0 Answers0