在R中使用Leaflet时缺少多边形

时间:2018-05-07 15:17:35

标签: r leaflet reproducible-research

我尝试重现代码以在另一台计算机的地图中显示多边形,但是,在一台计算机中,多边形未显示。共享代码时有人遇到过这种问题吗? 您可以从此处下载shapefile:http://www.conabio.gob.mx/informacion/metadata/gis/muni_2012gw.xml?_xsl=/db/metadata/xsl/fgdc_html.xsl&_indent=no

library(rgdal)
library(rgeos)
library(leaflet)

Mex <- readOGR(dsn="C:/DISCO D", layer="Muni_2012gw")
Mex_sub <- Mex[Mex$CVE_ENT=="01",]



bins <- quantile(Mex_sub@data$OID_1, c(0,.125,.25, .5, .75,.875, 1))
pal <- colorBin("YlOrRd", domain = Mex_sub@data$OID_1, bins = (bins),
                na.color = "grey40", reverse = FALSE)

centr <- gCentroid(Mex_sub)@coords
leaflet(Mex_sub, options = leafletOptions(minZoom = 4, maxZoom = 15)) %>% 
  addTiles() %>%
  setView(centr[1], centr[2], zoom = 8) %>%
  addPolygons(data=Mex_sub, weight = 1,fill = ~OID_1, fillColor = ~pal(OID_1),
              opacity=1, fillOpacity = 0.5, color=grey(0.5))

Map in my computer

Map in the other computer

0 个答案:

没有答案