我shapefile从data.gov下载了县。我可以在传单中使用它们,如下所示来绘制 WA、ID 和 OR 中的县。我想让州边界更厚。我怎样才能做到这一点?
counties <- readOGR(paste0(dir, "/tl_2017_us_county.shp"),
layer = "tl_2017_us_county", GDAL1_integer64_policy = TRUE)
counties <- counties[counties@data$STATEFP %in% c("16", "41", "53"), ]
counties <- subset(counties, STATEFP %in% c("16", "41", "53") )
counties <- rmapshaper::ms_simplify(counties)
counties %>%
leaflet() %>%
setView(lng = -118.4942, lat = 47.2149, zoom = 5) %>%
addPolygons( fillColor = "green", fillOpacity = 0.5,
color = "black", opacity = 1.0, weight = .6, smoothFactor = 0.5,
highlightOptions = highlightOptions(color="white", weight=2, bringToFront = TRUE),
label= ~ NAME)
Run Code Online (Sandbox Code Playgroud)
PS我想在R工作室中做到这一点,我不知道这里的任何高级编码:https : //leafletjs.com/
编辑 目标是使状态可区分,我做了以下工作:
factpal <- colorFactor(topo.colors(5), counties$category)
counties %>%
leaflet() %>%
# addTiles() %>%
setView(lng = -118.4942, lat = 47.2149, zoom = 5) %>%
addPolygons( fillColor = ~factpal(STATEFP), fillOpacity = 0.5,
# The following line is associated with borders
color = "black", opacity = 1.0, weight = .6, smoothFactor = 0.5,
highlightOptions = highlightOptions(color="white", weight=2, bringToFront = TRUE),
label= ~ NAME)
Run Code Online (Sandbox Code Playgroud)
还是想知道加粗边框的答案。
可能没有内置选项可以实现此目的,因为您正在尝试绘制属于一个州的所有县多边形的轮廓。当然,当您通过为状态内的所有多边形着色来突出显示状态时,它会起作用。
要通过 -package 实现您想要的效果,sp您可以执行以下操作:
library(sp)
library(leaflet)
states <- aggregate(counties[, "STATEFP"], by = list(ID = counties@data$STATEFP),
FUN = unique, dissolve = T)
counties %>%
leaflet() %>%
setView(lng = -118.4942, lat = 47.2149, zoom = 5) %>%
addPolygons( fillColor = "green", fillOpacity = 0.5,
color = "black", opacity = 1.0, weight = .6, smoothFactor = 0.5,
highlightOptions = highlightOptions(color="white", weight=2, bringToFront = TRUE),
label= ~ NAME) %>%
addPolylines(data = states, color = "black", opacity = 1, weight = 3)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1820 次 |
| 最近记录: |