title: Shade area under a curve
body: <p>I'm trying to shade an area under a curve in R.  I can't quite get it right and I'm not sure why.  The curve is defined by </p>
  
  <pre><code># Define the Mean and Stdev
  mean=1152
  sd=84
  
  # Create x and y to be plotted
  # x is a sequence of numbers shifted to the mean with the width of sd.  
  # The sequence x includes enough values to show +/-3.5 standard deviations in the data set.
  # y is a normal distribution for x
  x &lt;- seq(-3.5,3.5,length=100)*sd + mean
  y &lt;- dnorm(x,mean,sd)
  </code></pre>
  
  <p>The plot is </p>
  
  <pre><code># Plot x vs. y as a line graph
  plot(x, y, type="l")
  </code></pre>
  
  <p>The code I'm using to try to color under the curve where x >= 1250 is</p>
  
  <pre><code>polygon(c( x[x&gt;=1250], max(x) ),  c(y[x==max(x)], y[x&gt;=1250] ), col="red")
  </code></pre>
  
  <p>but here's the result I'm getting
  <a href="https://i.stack.imgur.com/2Dm00.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2Dm00.png" alt="enter image description here"></a>
  How can I correctly color the portion under the curve where x >= 1250</p>