title: Mapping Bus Routes with Leaflet in R
body: <p>I recently found this shape file of NYC bus routes <a href="https://wfs.gc.cuny.edu/SRomalewski/MTA_GISdata/nycbusroutes_100401_tripheadinfo.zip" rel="nofollow noreferrer">shape file of NYC bus routes (zip file)</a> that I am interested in plotting with the leaflet package in R.</p>
  
  <p>When I attempt to do so, some routes do not show up on the map. I can tell they're missing because I overlay the bus stop data and some do not line up with the routes. </p>
  
  <p>When I read in the shape file, I notice that the spatial lines data frame that is created has nested lists, which I think leaflet is not mapping. </p>
  
  <p>What do I need to do so that leaflet reads coordinates of these missing routes? Below is the code I used to produce the map with missing routes:</p>
  
  <pre><code>bus &lt;- readOGR(dsn = path.expand("bus_route_shapefile"), layer = "bus_route_shapefile")
  bus.pj &lt;- spTransform(bus, CRS("+proj=longlat +datum=WGS84"))
  bus.st &lt;- readOGR(dsn = path.expand("bus_stop_shapefile"), layer = "bus_stop_shapefile")
  bus.st.pj &lt;- spTransform(bus.st, CRS("+proj=longlat +datum=WGS84"))
  
  bus_map &lt;- leaflet() %&gt;%
    setView(lng = -73.932667, lat = 40.717266, zoom = 11) %&gt;%
    addPolylines(data = bus.pj, color = "black", opacity = 1) %&gt;%
    addCircles(data=bus.st.pj@data,~stop_lon, ~stop_lat, color = "red") %&gt;%
    addTiles()
  bus_map
  </code></pre>