【发布时间】:2015-11-20 06:28:24
【问题描述】:
我正在学习如何使用 R 和 Leaflet。我几乎完成了使用加利福尼亚县制作的地图,但我不喜欢在地图上看到其他州。我想将我的多边形(县)周围的地图涂白。我在其他地方看到了类似的问题,但我不知道将那里所说的内容应用到我的代码中。有人可以检查此代码并建议我需要添加的内容吗?
如果您滚动到此链接的底部,您会看到我正在尝试执行的操作。 http://rpubs.com/stefanya/127436
我使用的代码是:
#loading shapefile
counties <- readOGR("./shapefiles", layer="cb_2014_us_county_20m")
#filtering for only california
counties <- subset(counties, counties@data$STATEFP=="06")
#making a leaflet map of california counties
leaflet() %>% addTiles() %>% addPolygons(data=counties)
#merging the data into this shapefile
counties@data = data.frame(counties@data, sumByCounty[match(counties@data[,"NAME"], sumByCounty[,"NAME"]),])
#set color palette
colorRamp <- colorRamp(c("#2c7fb8","#7fcdbb","#edf8b1"), interpolate = "spline")
palette <- colorNumeric(colorRamp, counties@data$progress)
leaflet() %>% addProviderTiles("Stamen.TonerLite") %>%
addPolygons(
weight= 2,
stroke = TRUE,
fillOpacity = .65,
data=counties,
color = ~palette(progress),
popup = ~paste("<strong>County:</strong>",NAME,
"<br>",
"<strong>Total Responses:</strong>",sumByCounty,
"<br>",
"<strong>Complete:</strong>",progress,"<strong>%</strong>")
) %>% addLegend(title = "Response <br> Goal Met", pal = palette, values = counties@data$progress, bins=5, opacity = 1, position="topright", labFormat = labelFormat(suffix = '%'))
【问题讨论】:
-
一个简单的解决方法是在其他州上建立一个大多边形来隐藏它们……
-
您或许可以制作自己的自定义图块。 help.openstreetmap.org/questions/136/…
-
这是“在其他地方解决的类似问题”的链接:gis.stackexchange.com/questions/73048/… 因为它基本上是@ghybs 解决方法,并且可以很容易地应用于传单。
-
我认为这可能是个坏主意,因为很多有用的文本标签和其他注释会被剪掉,地图看起来会有点难看。给用户更多的上下文有什么问题?
-
因为没有给出可重现的例子而投反对票 - 使用 R 空间包之一提供的标准 shapefile 集之一怎么样?