title: Adding points from other dataset to ggplot2
body: <p>There are already many questions about this theme, but I could not find one that answered my specific problem.</p>
  
  <p>I have a <code>barplot</code> (see <code>testplot1</code> and <code>testplot3</code> below) plotting a dataset (<code>bardata</code> below) and want to add points to it from another dataset (<code>pointdata</code>). See the simplified example:</p>
  
  <pre><code>bardata &lt;- data.frame(
                 xname = c(1, 1, 1, 2, 2, 2, 3, 3, 3), 
                 yvalue = c(1, 2, 3, 2, 3, 1, 4, 2, 1), 
                 colorname = c("a", "b", "c", "a", "b", "c", "a", "b", "c")
                 )  
  pointdata &lt;- data.frame(
                  xname = c(1, 1, 3), 
                  ypos = c(2, 4, 3), 
                  ptyname = c("p", "q", "r")
               ) 
  
  testplot1 &lt;- qplot(xname, yvalue, data= bardata, stat = "identity", 
                 fill= factor(colorname),  geom = "bar")
  testplot2 &lt;- testplot1 + 
                  geom_point(data = pointdata, mapping = 
                    aes(x = xname, y = ypos, shape = factor(ptyname))
                  )
  </code></pre>
  
  <p>Now <code>testplot1</code> works perfectly fine, but <code>testplot2</code> gives the error</p>
  
  <blockquote>
    <p>Error in factor(colorname) : object 'colorname' not found.</p>
  </blockquote>
  
  <p>I do not understand why he says this, and would like to know, but this is not my main problem since there is an easy workaround, see <code>testplot3</code> below.</p>
  
  <pre><code> testplot3 &lt;- qplot(xname, yvalue, data= bardata, stat = "identity", 
                        fill= factor(bardata$colorname),  geom = "bar")
   testplot4 &lt;- testplot3 + 
                    geom_point(data = pointdata, mapping = 
                      aes(x = xname, y = ypos, shape = factor(ptyname)))
  </code></pre>
  
  <p>Now this time the program says: </p>
  
  <blockquote>
    <p>Error: Aesthetics must either be length one, or the same length as the
    dataProblems:xname, ypos, factor(ptyname).</p>
  </blockquote>
  
  <p>So my question is: what does this even mean? Obviously both <code>aes</code> and the data are of length 3. The number of rows in <code>pointdata</code> is less than that in <code>bardata</code>, but that is in itself not a problem, see for instance this answer: <a href="https://stackoverflow.com/a/2330825/2298323">https://stackoverflow.com/a/2330825/2298323</a></p>
  
  <p>So what is going on here? (And how do I get my points in my plot?) </p>