title: plotting two vectors of data on a GGPLOT2 scatter plot using R
body: <p>I've been experimenting with both <code>ggplot2</code> and <code>lattice</code> to graph panels of data. I'm having a little trouble wrapping my mind around the <code>ggplot2</code> model. In particular, how do I plot a scatter plot with two sets of data on each panel:</p>
  
  <p>in <code>lattice</code> I could do this:</p>
  
  <pre><code>xyplot(Predicted_value + Actual_value ~ x_value | State_CD, data=dd)
  </code></pre>
  
  <p>and that would give me a panel for each State_CD with each column</p>
  
  <p>I can do one column with <code>ggplot2</code>: </p>
  
  <pre><code>pg &lt;- ggplot(dd, aes(x_value, Predicted_value)) + geom_point(shape = 2) 
        + facet_wrap(~ State_CD) + opts(aspect.ratio = 1)
  print(pg)
  </code></pre>
  
  <p>What I can't grok is how to add Actual_value to the ggplot above. </p>
  
  <p><strong>EDIT</strong> Hadley pointed out that this really would be easier with a reproducible example. Here's code that seems to work. Is there a better or more concise way to do this with ggplot? Why is the syntax for adding another set of points to ggplot so different from adding the first set of data?</p>
  
  <pre><code>library(lattice)
  library(ggplot2)
  
  #make some example data
  dd&lt;-data.frame(matrix(rnorm(108),36,3),c(rep("A",24),rep("B",24),rep("C",24)))
  colnames(dd) &lt;- c("Predicted_value", "Actual_value", "x_value", "State_CD")
  
  #plot with lattice
  xyplot(Predicted_value + Actual_value ~ x_value | State_CD, data=dd)
  
  #plot with ggplot
  pg &lt;- ggplot(dd, aes(x_value, Predicted_value)) + geom_point(shape = 2) + facet_wrap(~ State_CD) + opts(aspect.ratio = 1)
  print(pg)
  
  pg + geom_point(data=dd,aes(x_value, Actual_value,group=State_CD), colour="green")
  </code></pre>
  
  <p>The lattice output looks like this:
  <a href="https://i.stack.imgur.com/G6rf7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G6rf7.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://www.cerebralmastication.com/wp-content/uploads/2009/08/lattice.png" rel="nofollow noreferrer">cerebralmastication.com</a>)</sub>  </p>
  
  <p>and ggplot looks like this:
  <a href="https://i.stack.imgur.com/bQb0N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bQb0N.png" alt="alt text"></a><br>
  <sub>(source: <a href="http://www.cerebralmastication.com/wp-content/uploads/2009/08/ggplot.png" rel="nofollow noreferrer">cerebralmastication.com</a>)</sub>  </p>