TransWikia.com

Map two sf objects on one map with mapview

Geographic Information Systems Asked on December 1, 2020

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

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

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

Correct answer by JRR on December 1, 2020

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

Answered by TimSalabim on December 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP