4

I have two sf objects, precincts and elemZones. I want to make a mapview object showing the boundaries of both sf objects, and I want to style each sf object differently. My code so far.

library(sf)
library(mapview)

precincts <- read_sf("precincts.shp")
elemZones <- read_sf("elemZones.shp")

mapview(
  x = elemZones,
  legend = F,
  color = "black",
  alpha.regions = 0,
  popup = F
)

This only maps elemZones. How do I add precincts?

2 Answers 2

4

mapview used to have a function addFeature() that is now in leafem

m <- mapview(elemZones, ...)
leafem::addFeatures(m, precincts)
4

If you want to style both of them can do

mapview(elemZones, ...) +
  mapview(precincts, ...)

where the ... here refer to additional styling.

If you only want to style one of them you can simply do

mapview(elemZones) +
  precincts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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