title: Creating base_layer for ggmap not recognizing data.frame
body: <p>I am trying to use ggmap to plot locations on a map. Because I want to use faceting, I have to supply the <code>base_layer</code> argument to <code>ggmap</code>. I am also trying to wrap this in a function.</p>
  
  <p>I have variables that define the bounding box of my map:</p>
  
  <pre><code>long.range &lt;- c(-71.5, -67.5)
  lat.range &lt;- c(42.5, 44.5)
  </code></pre>
  
  <p>And a data.frame that defines the data I want to plot:</p>
  
  <pre><code>test.data &lt;- data.frame("Name" = c("site1","site2","site3"),
                          "LAT" = c(43.25,43.4,44),
                          "LONG" = c(-71.25,-69.5,-68.5))
  </code></pre>
  
  <p>I have a function that goes out and grabs the map and applies the data.frame as the base_layer:</p>
  
  <pre><code>CreateBaseMap &lt;- function(lat.range = c(NA,NA),
                            long.range = c(NA,NA),
                            data.in = NULL){    
    # download the map tile
    base.map.in &lt;- get_map(location = c(min(long.range),
                                        min(lat.range),
                                        max(long.range),
                                        max(lat.range)),
                           source = "osm")
    # create the map object
    if (is.null(data.in)){
      base.map &lt;- ggmap(base.map.in)
    } else {    
      base.map &lt;- ggmap(base.map.in,
                        base_layer = ggplot(aes_string(x = "LONG",
                                                       y = "LAT"),
                                            data = data.in))
    }
    base.map &lt;- base.map +
      labs(x = "Longitude",
           y = "Latitude") + 
      coord_map()
    print(base.map)
    return(base.map)
  }
  </code></pre>
  
  <p>and then I call my function using</p>
  
  <pre><code>base.map &lt;- CreateBaseMap(lat.range = lat.range, long.range = long.range, data.in = test.data)
  </code></pre>
  
  <p>and I get this error.</p>
  
  <pre><code>Error in ggplot(aes_string(x = "LONG", y = "LAT"), data = data.in) : 
    object 'data.in' not found
  </code></pre>
  
  <h2>Troubleshooting so far</h2>
  
  <p>I know if I call the guts of the function directly, like this:</p>
  
  <pre><code>base.map &lt;- ggmap(get_map(location = c(min(long.range),
                                         min(lat.range),
                                         max(long.range),
                                         max(lat.range)),
                            source = "osm"),
                    base_layer = ggplot(aes_string(x = "LONG",
                                                   y = "LAT"),
                                        data = test.data)) +
    geom_point()
  print(base.map)
  </code></pre>
  
  <p>then it works fine.</p>
  
  <p><img src="https://i.stack.imgur.com/VLET9.png" alt="The image I want"></p>
  
  <p>I have also checked using <code>print(data.in)</code> that the data.in exists before it gets to the call to <code>base_layer</code>, and I can see that it's there.</p>
  
  <h2>Question</h2>
  
  <p>It appears that the call to <code>base_layer</code> doesn't recognize <code>data.in</code>. </p>
  
  <ol>
  <li>How can I persuade <code>base_layer</code> that it really wants to accept <code>data.in</code>?</li>
  <li>Is this a problem with <code>ggplot</code>, or am I doing something wrong?</li>
  </ol>