Map one EJSCREEN indicator at blockgroup resolution
Source:R/map_ejscreen_indicator.R
map_ejscreen_indicator.RdDraw a Leaflet or ggplot choropleth for one county or state using raw
values already in blockgroupstats and percentiles from lookup_pctile().
No EJAM analysis is run. The Leaflet map includes indicator values, percentiles,
blockgroup FIPS codes, and population (when available) in its popups.
Usage
map_ejscreen_indicator(
indicator = "pctlowinc",
countyfips = NULL,
ST = NULL,
zoom = NULL,
scope = c("national", "state"),
blockgroup_data = blockgroupstats,
shp = NULL,
lookup = NULL,
index_data = NULL,
colorbins = c(0, ejscreen_color_defaults()$colorbins, 100),
colorfills = ejscreen_color_defaults()$colorfills,
colorlabels = NULL,
na.color = "#D3D3D3",
fillOpacity = 0.7,
maptype = c("leaflet", "ggplot"),
year = NULL,
cb = TRUE
)Arguments
- indicator
One raw indicator name, such as
"pctlowinc","proximity.npl", or"EJ.DISPARITY.pm.eo". A"pctile."or"state.pctile."prefix is also accepted and selects the percentile scope.- countyfips
One county FIPS code, or a FIPS code whose parent county can be resolved by
fips2countyfips(). Numeric codes are normalized to include leading zeros.- ST
One state abbreviation, state name, or two-digit state FIPS code.
- zoom
Optional initial Leaflet zoom level from 0 to 18. If NULL, fit the view to all selected blockgroup polygons.
- scope
"national"(default) or"state"percentile distribution. An explicitly supplied scope must agree with any percentile prefix.- blockgroup_data
A data.frame or data.table with bgfips and raw indicator columns; defaults to the package's blockgroupstats.
- shp
Optional sf blockgroup polygons with a FIPS, GEOID, or bgfips column and a known coordinate reference system. May contain additional polygons. Missing or empty boundaries are omitted with a warning; duplicate FIPS matches are rejected. At least one drawable polygon is required.
- lookup
Optional percentile lookup table; defaults to usastats or statestats according to scope. Must contain REGION, PCTILE, and the indicator.
- index_data
Optional bgej-like table of Summary Index scores, joined by bgfips. If needed and omitted, bgej is loaded using
dataload_dynamic().- colorbins
Percentile bin boundaries INCLUDING 0 and 100. Defaults to the shared package cutoffs. A cutoff belongs to the higher bin.
- colorfills
One fill color per bin, from the shared package defaults.
- colorlabels
Optional legend labels, one per bin. Standard bins use the shared labels; custom bins get interval labels automatically.
- na.color
Fill color for missing percentiles, labeled "No data" in the legend when needed.
- fillOpacity
Polygon fill opacity between 0 and 1.
- maptype
Either "leaflet" (default) for an interactive map or "ggplot" for a static map using the same percentile colors and legend. zoom is only used by Leaflet.
- year
Census boundary year; defaults to
acs_endyear()to match the package's ACS data vintage. Ignored when shp is supplied.- cb
TRUE (default) for smaller generalized cartographic boundaries; FALSE for detailed TIGER/Line boundaries. Generalized boundaries are much faster to download and draw, but simplified and clipped along shorelines; use them for overview maps, not precise spatial analysis. Both choices reuse cached state files. Ignored when shp is supplied.
Value
A Leaflet htmlwidget or a ggplot object. The ggplot object's data contains the selected raw indicator values and a .map_percentile column.
Details
Specify exactly one of countyfips or ST. National percentiles are the default, even when only one county or state is displayed. State percentiles use that state's lookup distribution, not the selected county. State demographic and EJ indexes use their state-specific raw scores. EJ/Supplemental Summary Index scores are read from bgej when they are not already present in blockgroup_data.
Only the selected scope is mapped. Panning or zooming does not load more blockgroups, and tract aggregation is not provided. Boundaries are downloaded as one state file through tigris and cached for reuse. Generalized cartographic boundaries are the default; large states can still take time to render. Supply shp to reuse polygons without downloading anything.
Examples
if (FALSE) { # \dontrun{
map_ejscreen_indicator("pctlowinc", countyfips = fips_from_name("Cook County, IL"))
map_ejscreen_indicator("pctlowinc", countyfips = "10001")
map_ejscreen_indicator("pctile.proximity.npl", countyfips = "10001", zoom = 10)
map_ejscreen_indicator("state.pctile.pctlowinc", ST = "DE")
map_ejscreen_indicator("pctlowinc", ST = "IL")
map_ejscreen_indicator("pctlowinc", ST = "IL", maptype = "ggplot")
# Reuse boundaries instead of downloading them again.
bg <- blockgroupstats[substr(bgfips, 1, 5) == "10001", ]
polygons <- shapes_from_fips(bg$bgfips)
map_ejscreen_indicator("pm", countyfips = "10001", shp = polygons)
} # }