title: Changing line color in ggplot based on slope
body: <p>I have the following code which plots points and draw a line between them. </p>
  
  <pre><code>ggplot (data = subset(df, vowel == "O" &amp; gender == "f"), aes (x = time, y = val, color = formant)) +
        geom_point()+
        geom_line(aes(group=interaction(formant, number)))
  </code></pre>
  
  <p>It produces this:</p>
  
  <p><a href="https://i.stack.imgur.com/l2dAH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l2dAH.png" alt="enter image description here"></a></p>
  
  <p>Is there a way to group these by color/line type for negative slopes vs. positive slopes of these lines?</p>
  
  <p>edit:
  Here is my data:</p>
  
  <pre><code>number &lt;- c(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)
  formant &lt;- c("F2", "F2", "F2", "F2", "F2", "F2", "F3", "F3", "F3", "F3", "F3", "F3")
  time &lt;- c(50, 50, 50, 99, 99, 99, 50, 50, 50, 99, 99, 99)
  val &lt;- c(400, 500, 600, 450, 550, 650, 300, 400, 500, 250, 350, 450)
  </code></pre>
  
  <p>I want to show movement of in the value of <code>val</code> over <code>time</code> grouped by <code>formant</code> and <code>number</code>. So when I implement the answer, it tells me I have an incompatible size, which I think has something to do with the fact that it's grouped by number. </p>