将州边界添加到传单的输出中,其中输入是县 shapefile

No *_*Lie 5 r r-sp r-leaflet

shapefiledata.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)

还是想知道加粗边框的答案。

在此处输入图片说明

Hum*_*hen 5

可能没有内置选项可以实现此目的,因为您正在尝试绘制属于一个州的所有县多边形的轮廓。当然,当您通过为状态内的所有多边形着色来突出显示状态时,它会起作用。

要通过 -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)

在此输入图像描述