Shading under specific total percentage of a density chart

I'm creating a density plot in ggplot2 using geom_density. Is there a way to highlight the first 50% of cumulative density? So in the attached chart (see image) it would shade the left half of the chart until the cumulative density hits 50%.

Or is there a way to calculate the x value at which the cumulative density hits 50%? Thanks for the help!

In general, this is possible. Please provide your code or an example using some toy data and I am sure we can help you.

The general idea would be: calculate the median and, within the ggplot, to split the data into lower and higher groups based on this threshhold.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.