title: How to add geo-spatial connections on a ggplot map?
body: <p>Using <a href="http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/" rel="nofollow">this</a> as a reference, I'm trying to plot a map of the lower forty-eight and add layers to visualize flow between states.</p>
  
  <pre><code>library(ggplot2)
  library(maps)
  library(geosphere) # to inter-polate a given pair of (lat,long) on the globe
  
  # load map data for the US
  all_states &lt;- map_data("state")
  
  # plot state map
  p &lt;- ggplot() + geom_polygon( data=all_states, 
                         aes(x=long, y=lat, group = group),
                         colour="white", fill="grey10" )
  
  # sample origin - destination lat,long pairs
  geo &lt;- structure(list(orig_lat = c(36.17, 36.17, 36.17), 
  orig_lon = c(-119.7462, -119.7462, -119.7462), dest_lat = c(33.7712, 36.17, 39.0646), 
      dest_lon = c(-111.3877, -119.7462, -105.3272)), .Names = c("orig_lat", 
  "orig_lon", "dest_lat", "dest_lon"), row.names = c(NA, 3L), class = "data.frame")
  
  #&gt; geo
  #  orig_lat  orig_lon dest_lat  dest_lon
  #1    36.17 -119.7462  33.7712 -111.3877
  #2    36.17 -119.7462  36.1700 -119.7462
  #3    36.17 -119.7462  39.0646 -105.3272
  
  # list to hold a dataframe of interpolated points for each origin-destination pair
  list_lines &lt;- list()
  
  # use the geosphere package's gcIntermediate function to generate 50 interpolated  
  # points for each origin-destination pair
  for (i in 1:3) {
    inter &lt;- as.data.frame(gcIntermediate(c(geo[i,]$orig_lon, geo[i,]$orig_lat), 
                                          c(geo[i,]$dest_lon, geo[i,]$dest_lat), 
                                          n=50, addStartEnd=TRUE))
    list_lines[i] &lt;- list(inter)
    p &lt;- p + geom_line( data = list_lines[[i]], aes(x = lon, y = lat), color = '#FFFFFF')
  }
  p
  </code></pre>
  
  <p>Here is what I get when I try to print the plot</p>
  
  <pre><code>p
  Error in eval(expr, envir, enclos) : object 'lon' not found
  </code></pre>
  
  <p>I tried to debug this and found that this works</p>
  
  <pre><code>p + geom_line( data = list_lines[[1]], aes(x = lon, y = lat), color = '#FFFFFF')
  </code></pre>
  
  <p>but adding another layer for the second list element breaks it, but that's as far as I could get with my limited knowledge of both R and ggplot!</p>