title: r - ggplot2 - highlighting selected points and strange behavior
body: <p>I want to highlight selected points and encountered some strange behaviour. First some dummy data:</p>
  
  <pre><code>a &lt;- 1:50
  b &lt;- rnorm(50)
  mydata &lt;- data.frame(a=a,b=b)
  ggplot(mydata,aes(x=a,y=b)) + geom_point()
  </code></pre>
  
  <p>This works correctly. Now,to highlight some points, I add another <code>geom_point</code> layer:</p>
  
  <pre><code>ggplot(mydata[20:40,],aes(x=a,y=b)) + 
      geom_point() + 
      geom_point(aes(x=a[c(10,12,13)],y=b[c(10,12,13)]),colour="red")
  </code></pre>
  
  <p>Note that I am displaying only a limited range of the data (<code>[20:40]</code>).  Now comes the strange behavior:</p>
  
  <pre><code>ggplot(mydata[10:40,],aes(x=a,y=b)) + 
      geom_point() + 
      geom_point(aes(x=a[c(10,12,13)],y=b[c(10,12,13)]),colour="red")
  </code></pre>
  
  <p>Changing the size of the selected range, I get an error, roughly translated from German: <code>Error...: Arguments implying different number of rows</code>. Strangely, this varies with the selected range. <code>[23:40]</code> will work, <code>[22:40]</code> won't.</p>
  
  <hr>
  
  <p>The error in English is:</p>
  
  <pre><code>Error in data.frame(x = c(19L, 21L, 22L), y = c(0.28198, -0.6215,  : 
    arguments imply differing number of rows: 3, 31
  </code></pre>