title: Calculate Area Between 2 Curves
body: <p>I would like to calculate the area between the blue line and the gray diagonal line. </p>
  
  <p><img src="https://i.stack.imgur.com/rfXrW.png" alt="enter image description here"></p>
  
  <p>I can calculate the area under the blue line as:</p>
  
  <pre><code>library(zoo)    
  id &lt;- order(x)
  AUC &lt;- sum(diff(x[id])*rollmean(y[id],2))
  </code></pre>
  
  <p>(thanks to <a href="https://stackoverflow.com/questions/4954507/calculate-the-area-under-a-curve-in-r">Calculate the Area under a Curve in R</a>)</p>
  
  <p>Any ideas how to find the area between the blue and gray line?</p>
  
  <p>Thanks in advance
  EC</p>