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,
...
)
a leaflet
map, eg from oh_map()
a sf
polygon data frame
an unquoted field name (see tidy-select
) for the column in
ply
containing the value to map
an unquoted field name (see tidy-select
) for the column in
ply
containing the identifier to include in the popup
the string name for the field value in the legend and popup
the string name for the identifier in the popup
the divergent midpoint of the field value fld_val
for
setting as the midpoint of the color palette col_pal
; default is NULL
color palette for the polygon fill color; default is "Spectral"
fill opacity; default is 0.6
border color; default is "gray"
border opacity; default is 0.9
border weight; default is 1
logical of whether to add legend; default is TRUE
additional arguments passed onto leaflet::addPolygons()
a leaflet::leaflet()
map
# 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 "%>%"