title: How can i use ggplot in R to make a scatterplot where the colour varies depending on if y>x or y<x?
body: <p>I would like make a graph where if the value of x is greater than the value of y, the point is a colour and if it is less than y it is another color. </p>
  
  <p>Here is the code I've come up with:</p>
  
  <pre><code>df = read.table(text = 
            "C1         C2 
          2003          2030
          2001          2301
          2005          2002
          2333          2003
          5466          4444
          2000          2002
          2222          2223
          1000          2032
      ", sep = "", header = TRUE)
  p2 &lt;- vector()
  p3 &lt;- vector()
  for (i in 1:length(A$C1))
    {if(A$C2[i]&gt;=A$C1[i]) {
    p2[i] &lt;- A$C1[i]
  }else
  if(A$C2[i]&lt;=A$C1[i]){
    p3[i] &lt;- A$C1[i]
  }
  }
  p &lt;- ggplot(data=Movie, aes(x=C1, y=C2))+ 
    ylab("C2")+
    xlab("C1")+
    ggtitle("C1 on C2")+
    geom_smooth(method = lm)+
    geom_point(aes(x=p2), color="blue")+
    geom_point(aes(x=p3), color="green")
  p
  </code></pre>
  
  <p>My problem I think is that loop, it gives me a bunch of NAs that cannot be used by the geom_point() function. 
  Thank you.</p>