使用 R 中的 Leaflet 通过 readOGR / addPolygon() 添加地理多边形

Adding geographic polygons via readOGR / addPolygon() with Leaflet in R

我一直在学习本教程,但出于某种原因,我似乎无法将这些自治市镇多边形显示在传单中。如果我这样做

plot(boroughs)

一切正常,您可以清楚地看到 shapefile 已加载并可以使用。尽管如此,使用下面的代码它不起作用。我缺少什么才能让这些形状显示在我的传单地图上?

#load libraries
library(leaflet)
library(rgdal)

#available at http://www1.nyc.gov/assets/planning/download/zip/data-maps/open-data/nybb_15d.zip
boroughs <-readOGR("C:/Users/580048/Documents/nybb_15b/nybb.shp","nybb")

leaflet(boroughs) %>%
  addProviderTiles("CartoDB.DarkMatterNoLabels", 
                   options= providerTileOptions(opacity = 0.99)) %>%

  addPolygons(
    stroke = FALSE, 
    smoothFactor = 0.5) %>%

  fitBounds(-73.9, 40.7, -73.7, 40.9) 

需要转换坐标,注意我不确定这是正确的投影

library("leaflet")
library("rgdal")
boroughs <- readOGR(path.expand("~/Downloads/nybb_15d/nybb.shp"), "nybb")
boroughs <- spTransform(boroughs, CRS("+proj=longlat +datum=WGS84"))
leaflet() %>%
  addProviderTiles("CartoDB.DarkMatterNoLabels", 
                   options= providerTileOptions(opacity = 0.99)) %>%
  addPolygons(data = boroughs,
    stroke = FALSE, 
    smoothFactor = 0.5) %>%
  fitBounds(-73.9, 40.7, -73.7, 40.9)