Add polygons to an interactive choropleth map, optionally with a color scheme that diverges around a midpoint value.

oh_add_ply(
  map,
  ply,
  fld_val,
  fld_id,
  str_val,
  str_id,
  div_mid = NULL,
  col_pal = "Spectral",
  fill_opacity = 0.6,
  brdr_color = "gray",
  brdr_opacity = 0.9,
  brdr_weight = 1,
  add_legend = T,
  ...
)

Arguments

map

a leaflet map, eg from oh_map()

ply

a sf polygon data frame

fld_val

an unquoted field name (see tidy-select) for the column in ply containing the value to map

fld_id

an unquoted field name (see tidy-select) for the column in ply containing the identifier to include in the popup

str_val

the string name for the field value in the legend and popup

str_id

the string name for the identifier in the popup

div_mid

the divergent midpoint of the field value fld_val for setting as the midpoint of the color palette col_pal; default is NULL

col_pal

color palette for the polygon fill color; default is "Spectral"

fill_opacity

fill opacity; default is 0.6

brdr_color

border color; default is "gray"

brdr_opacity

border opacity; default is 0.9

brdr_weight

border weight; default is 1

add_legend

logical of whether to add legend; default is TRUE

...

additional arguments passed onto leaflet::addPolygons()

Value

a leaflet::leaflet() map

Examples

# map zones by area
oh_map() %>%
oh_add_ply(
  ply     = oh_zones_s1k,
  fld_val = area_km2,
  fld_id  = zone_name,
  str_val = "area (km^2)",
  str_id  = "Zone")
#> Error in oh_map() %>% oh_add_ply(ply = oh_zones_s1k, fld_val = area_km2,     fld_id = zone_name, str_val = "area (km^2)", str_id = "Zone"): could not find function "%>%"

# map zones by area with divergent color scheme around mean
oh_map() %>%
oh_add_ply(
  ply     = oh_zones_s1k,
  fld_val = area_km2,
  fld_id  = zone_name,
  str_val = "area (km^2)",
  str_id  = "Zone",
  div_mid = mean(oh_zones$area_km2))
#> Error in oh_map() %>% oh_add_ply(ply = oh_zones_s1k, fld_val = area_km2,     fld_id = zone_name, str_val = "area (km^2)", str_id = "Zone",     div_mid = mean(oh_zones$area_km2)): could not find function "%>%"