title: Filling cross over under a Cumulative Frequency plot using ggplot in R
body: <p>I am trying to plot two Cumulative Frequency curves in ggplot, and shade the cross over at a certain cut off. I haven't been using ggplot for long, so I was hoping someone might be able to help me with this one. </p>
  
  <p>The plot without filled regions, looks like this... <img src="https://i.stack.imgur.com/rJIG7.png" alt="Cumulative Frequency for North and South regions"></p>
  
  <p>Which I have created using the following code... </p>
  
  <pre><code>library(ggplot2) # required 
  
  north &lt;- rnorm(3060, mean=277,sd=3.01) # to create synthetic data 
  south &lt;- rnorm(3060, mean=278, sd=3.26) # in place of my real data. 
  
  #placing in dataframe
  df_temp &lt;- data.frame(temp=c(north,south), 
      region=c(rep("north",length=3060),rep("south",length=3060)))
  
  #manipulating into cdf, as I've seen in other examples
  temp.regions &lt;- ddply(df_temp, .(region), summarize,
                            temp = unique(temp),
                            ecdf = ecdf(temp)(unique(temp)))
  
  # feeding into ggplot. 
   ggplot(temp.regions,aes(x=temp, y=ecdf, color = region)) + 
        geom_line(aes(x=temp,color=region))+
        scale_colour_manual(values = c("blue","red"))
  </code></pre>
  
  <p>What I would then like, would be to shade both curves for temperatures below 0.2 on the y axis. Ideally I'd like to see the blue one shaded in blue, and the red one shaded in red. Then, where they cross over in purple. </p>
  
  <p>However, the closest I have managed is as follows... <img src="https://i.stack.imgur.com/Vw64Q.png" alt="My first attempt at getting areas under the curve">]</p>
  
  <p>Which I have achieved using the following additions to my code. </p>
  
  <pre><code># creating a dataframe with just the temperatures for below 0.2
  # to try and aid control when plotting
  temp.below &lt;- temp.regions[which(temp.regions$ecdf&lt;0.2),]
  
  # plotting routine again. 
  ggplot(temp.regions, aes(x=temp, y=ecdf, color = region)) + 
    geom_line(aes(x=temp,color=region))+
    scale_colour_manual(values = c("blue","red"))+
  # with additional line for shading.
    geom_ribbon(data=temp.below,
                aes(x=temp,ymin=0,ymax=0.2), alpha=0.5)
  </code></pre>
  
  <p>I've seen a few examples of people shading for a normal distribution density plot, which is where I have adapted my code from. But for some reason my boxes don't seem to want anything to do with the temperature curve. </p>
  
  <p>Please help! I'm sure it's quite simple, I'm just really lost and have tried a few, producing less convincing results than these. </p>
  
  <p>Thank you so much for taking a look. </p>
  
  <p>PROBLEM SOLVED THANKS TO HELP BELOW... </p>
  
  <p>running suggested code from below </p>
  
  <pre><code>geom_ribbon(aes(ymin=0,ymax=ecdf, fill=region), alpha=0.5)
  </code></pre>
  
  <p>gives... </p>
  
  <p><img src="https://i.stack.imgur.com/c4Auu.png" alt="enter image description here"></p>
  
  <p>which is so very almost the solution I'm after, but with one final addition... like so</p>
  
  <pre><code>#geom_ribbon(aes(ymin=0,ymax=ecdf, fill=region), alpha=0.5)
  geom_ribbon(data=temp.below, aes(ymin=0,ymax=ecdf, fill=region), alpha=0.5)
  </code></pre>
  
  <p>I get what I'm after... <img src="https://i.stack.imgur.com/PflD6.png" alt="enter image description here"></p>
  
  <p>The reason I set the data again is so that it only fills the lowest 20% of the two regions. </p>
  
  <p>Thank you so much for the help :-) </p>