1

I have a shapefile of neighborhood areas in NYC (https://nycopendata.socrata.com/City-Government/Neighborhood-Tabulation-Areas/cpf4-rkhq).

When I use use leaflet to overlay these polygons the background tiles are not shown.

This is the code I am using:

library(rgdal)
library(leaflet)
nyc = readOGR("geo_export_da30afd0-e475-44e2-90d2-aca31344ef5e.shp",
               layer="geo_export_da30afd0-e475-44e2-90d2-aca31344ef5e")
m = leaflet() %>% fitBounds(lng1 = -74.458921, lat1 = 40.550302, 
                            lng2 = -73.683035, lat2=40.89225)
m %>% addTiles()
m %>% addPolygons(data=nyc)

This is the output: enter image description here

Eadan Fahey
  • 353
  • 2
  • 11

1 Answers1

2
m %>% addTiles() %>% addPolygons(data = nyc) 

should work. %>% does not assign but only pipes contents, therefore needs to be a complete chain.

TimSalabim
  • 5,604
  • 1
  • 25
  • 36