title: Is it possible to apply color gradient to geom_smooth with ggplot in R?
body: <p>I would like to apply the scale colour gradient also to the smooth line.
  At the moment the code below set the color fix to red.</p>
  
  <pre><code>library(ggplot2)
  a &lt;- data.frame(year = 1:100, values = sin(1:100)*1000 + runif(100))
  ggplot(a, aes(x = year, y = values, color = values )) + geom_line(size = 2)  +
  scale_colour_gradient2(
    low = "blue",
    mid = "white" ,
    high = "red",
    midpoint = 10
   )+
  geom_smooth(
   data = a,
   aes(x = year, y = values),
   color = "red",
   size = 2
   )
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vZYSt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vZYSt.png" alt="enter image description here"></a></p>
  
  <p>But when I set <code>color = values</code> it doesn't work. Instead it takes the default blue.</p>
  
  <pre><code>geom_smooth(
   data = a,
   aes(x = year, y = values, color = values),
   size = 2
   )
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/3MakV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3MakV.png" alt="enter image description here"></a></p>
  
  <p>Thanks in advance.</p>