title: filling color gridient under normal curve in X direction in r
body: <p>I am trying to shade under curve (contrast to y direction in <a href="https://stackoverflow.com/questions/15012188/r-plot-normal-curves-with-color-gradient">this post</a>). Just the following is hypothesis of filling direction.</p>
  
  <pre><code>curve(dnorm(x,0,1),xlim=c(-3,3),main='Standard Normal')
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/eHbzX.jpg" alt="enter image description here"></p>
  
  <p>I am trying to write a function, where I can fill very small polygons with different colors ( I do not know if this is right approach), then it will look like gradient.</p>
  
  <p>The idea is to extend the following filling of single polygon to n polygons.</p>
  
  <pre><code>codx &lt;- c(-3,seq(-3,-2,0.01),-2)
  cody &lt;- c(0,dnorm(seq(-3,-2,0.01)),0)
  
   curve(dnorm(x,0,1),xlim=c(-3,3),main='Standard Normal')
   polygon(codx,cody,col='red')
  </code></pre>
  
  <p>I tried to extend it to a function: 
       x1 &lt;- NULL
      y1 &lt;- NULL</p>
  
  <pre><code>polys &lt;- function ( lwt, up, itn) {
      x1 &lt;- c(lwt,seq(lwt,up, itn),up)
      y1 &lt;- c(0,dnorm(seq(lwt,up,tn)),0)
      out &lt;- list (x1, y1)
      return (out)
      }
  out &lt;- polys(lwt = 0, up = 1, itn = 0.1)
  
  library(RColorBrewer)
  plotclr &lt;- brewer.pal(10,"YlOrRd")
  </code></pre>
  
  <p>Neither I could workout the function nor I could brew more colors than 9 this way. Help appreciated. </p>