1

I am using leaflet in R to make maps with layers. I have the basics down but am new to geoJson and would like to be able to show grouped territories outlined. For example, I would like to group “western” states of CA, NV, WA and show a polygon that is the outside border of all those states.

I see how to show the full borders of the polygons, but am lost on how to start making a polygon that is the continuous border of all those states mushed together.

Thank you!

The best I’ve gotten so far is outlining each polygon on the map (current layer is US states, but I have countries of the world I will need to outline as well).

1 Answer 1

1

You can just group or filter the states you want to outline and call the summarise function.

library(sf)
library(dplyr)
library(leaflet)

states <- read_sf("https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json")

western_states <- states %>% 
  dplyr::filter(name %in% c("California", "Nevada", "Oregon", "Washington")) %>% 
  summarise(Category="Western States") 

leaflet() %>%
  addTiles() %>%
  addPolygons(data=western_states, fill=F, color="black", opacity=1)

enter image description here

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.