Map - County polygons / boundaries - Create leaflet or static map of results of analysis
Source:R/MAP_FUNCTIONS.R
mapfastej_counties.RdMap - County polygons / boundaries - Create leaflet or static map of results of analysis
Usage
mapfastej_counties(
mydf,
colorvarname = "pctile.Demog.Index.Supp",
colorfills = c("darkgray", "yellow", "orange", "darkred"),
colorlabels = ejscreen_color_defaults()$colorlabels,
colorbins = c(0, ejscreen_color_defaults()$colorbins, 100),
colorpalette = ejscreen_color_defaults()$colorfills,
static_not_leaflet = FALSE,
main = "Selected Counties",
fillOpacity = 0.5,
ST = "DE",
...
)Arguments
- mydf
something like ejamit(fips = fips_counties_from_statename("Kentucky"), radius = 0)$results_bysite
- colorvarname
colname of indicator in mydf that drives color-coding (or alternatively, colorvarname = "green" means a single specific color for all, like "green")
- colorfills
Vector of colors shown in the legend. The historical default is darkgray, yellow, orange, and darkred. Set this to the same colors as colorpalette to match the polygon fills exactly. (For a column that is not a percentile, the legend already uses the colors of colorpalette if these are left at their defaults – see details.)
- colorlabels
Vector of text labels shown in the legend, one per bin.
- colorbins
Increasing bin boundaries INCLUDING endpoints; the default is c(0, 80, 90, 95, 100). A cutoff belongs to the higher bin, and 100 is included in the last bin. A single number requests Leaflet's bin-count mode.
- colorpalette
Palette for filling polygons, default gray, yellow, orange, and red from
ejscreen_color_defaults().- static_not_leaflet
set TRUE to use
map_shapes_plot()instead ofmap_shapes_leaflet()- main
title for map
- fillOpacity
passed to
map_shapes_leaflet()which passes it toleaflet::addPolygons()- ST
ignored if mydf is provided. If mydf is omitted, ST can be the 2-character abbreviation of a State, and the function will run the analysis of all counties in that state before drawing the map.
- ...
depending on value of static_not_leaflet T/F, passed to
map_shapes_plot()or tomap_shapes_leaflet()which passes it toleaflet::addPolygons(), such as opacity=1
Value
leaflet html widget (but if static_not_leaflet = TRUE, returns just shapes_from_fips(mydf$ejam_uniq_id), which has one row per row of mydf, with an empty shape for an invalid site). Returns NULL, with a warning, if there is nothing to map.
Details
This assumes that mydf$ejam_uniq_id contains county FIPS codes.
Rows of mydf that are invalid sites, such as an invalid FIPS code, are not mapped. Each county that is mapped keeps its own color and popup.
If colorvarname is a numeric column that is not a percentile (and colorbins, colorfills, colorlabels and colorpalette are left at their defaults), the same 4 colors are used with cutoffs at the 80th, 90th and 95th percentiles of the values of the counties that are mapped. The legend shows those cutoffs, in the same colors as the counties (colorpalette).
For standard percentile columns produced by ejamit(), a county's
aggregated indicator score is compared with the blockgroup distribution
in the US or its State, depending on colorvarname. A county shown at the
90th percentile has an aggregated score at approximately the 90th
percentile of that blockgroup distribution. It is not ranked against
other counties, and this is not the average of its blockgroup percentiles.
Examples
if (FALSE) { # \dontrun{
myfips = fips_counties_from_state_abbrev(c("AL", "GA", "MS"))
mydf = ejamit(fips = myfips )$results_bysite
mapfastej_counties(mydf, colorvarname = "pctile.pctnhba")
# Analyze and map all counties in one state without supplying mydf.
mapfastej_counties(ST = "DE", colorvarname = "state.pctile.o3")
# Keep the legend colors identical to the polygon palette.
colors <- EJAM:::ejscreen_color_defaults()$colorfills
mapfastej_counties(mydf, colorpalette = colors, colorfills = colors)
} # }