title: R: ggplot (x,y,z) create multiple linear regression lines for different z values
body: <p>I have an interpolated DF with <strong>x, y and z</strong> data.</p>
  <p><em>x values ranges between -250 and +2000, Y values between -2 and +2 and z values between 75 and 90.</em></p>
  <p>With ggplot2 I've created a 2D plot (geom_raster) with <strong>fill = z</strong> which results in a heatmap for the different z values.</p>
  <p>Now I want to create multiple linear regression lines for different z-values (e.g. a &quot;lm&quot; for z = 80, z= 85, and so on) and add them over the geom_raster plot including a legend.</p>
  <p>How can I do this?
  Please tell me if I didn't specify something exactly.</p>
  <p>edit:
  this is how my ggplot looks like:</p>
  <pre><code>plot &lt;- interpdf %&gt;%
    filter(!is.na(z)) %&gt;%
    tbl_df() %&gt;%
    ggplot(aes(x = x, y = y, z = z, group = z)) + 
    geom_raster( aes(fill = z), interpolate = FALSE, alpha=alpha) +
    scale_x_continuous(limits = c(-200,2300))+
    scale_y_continuous(limits = c(-1.8,1.5))+
    geom_contour(color = color, alpha = 0.1) + 
    scale_fill_distiller(palette=&quot;YlGnBu&quot;, na.value=&quot;white&quot;)
  </code></pre>
  <p>whereas the interpdf data  looks like this:</p>
  <pre><code>   x      y       z
  ---------------------
  -2100    -2.4    83.5
  956.4    -1.3    84.3
  1255.1   1.34    88.9    
  ...      ...     ...
  </code></pre>
  <p>Here is what my plot looks like:
  <a href="https://i.stack.imgur.com/oVORG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oVORG.png" alt="enter image description here" /></a></p>