Map an ACS variable by tract in a drive-time area (map 3 of 4)
Source:R/plot-site.R
cacs_plot_site_weighted.RdDraws an interactive leaflet map of one American Community Survey (ACS)
variable over the census tracts that overlap a drive-time area of a site.
The part of each tract inside the area is shaded by the tract's estimate
as it is in acs_sf, before any weighting. The outline of the area and
the site's point are drawn on top.
Usage
cacs_plot_site_weighted(
site_id = NULL,
lat = NULL,
lon = NULL,
site_name = NULL,
iso_sf,
tract_sf,
acs_sf,
sites_df = NULL,
variable = "B17001_002",
tiles = "OpenStreetMap",
padding_km = 5,
drive_time_min = NULL,
variable_family = "spatial_total",
...
)Arguments
- site_id
A string giving the
site_idof the site to map, used to find its point insites_dfand its drive-time areas iniso_sf.- lat, lon
Single numbers giving the latitude and longitude of a point in degrees (WGS 84), used when
site_idisNULL. Both must be given. The point is marked at that location, and the areas of every site iniso_sfare used.- site_name
A string giving the name of the site, compared with the
site_namecolumn ofsites_dfincluding case, and used whensite_id,lat, andlonareNULL. It must match one row.- iso_sf
An
sfobject of drive-time areas in EPSG:4326 (longitude and latitude), such as the result ofcacs_isochrone(), with the columnssite_idanddrive_time_min.- tract_sf
An
sfobject of census tract polygons with aGEOIDcolumn, such as the result ofcacs_acs_prefetch(). When a tract has several rows, as in that result (one for each variable), the first row is used.- acs_sf
A data frame or
sfobject of tract estimates in the long form of the result ofcacs_acs_prefetch(), with the columnsGEOID,variable,estimate, andmoe. It is often the same object astract_sf. The estimates are mapped as they are: unlikecacs_intersect_weight(), the map does not set Census Bureau annotation codes, such as-666666666, toNA, and it draws a tract with two rows for the variable twice instead of giving an error.- sites_df
An
sfobject of site points in longitude and latitude with asite_idcolumn, orNULL(the default) forcacs_alabama_sites. The bundled filelegacy_2025_isochrones.rdsuses the samesite_idvalues for other places, so with its areas the default puts the point and the initial view far from them.- variable
A string giving the ACS variable code to map, one of the values in the
variablecolumn ofacs_sf. The default is"B17001_002", the number of people whose income in the past 12 months was below the poverty level.- tiles
A string naming the background map, one of the tile providers in
leaflet::providers; the default is"OpenStreetMap", the standard OpenStreetMap map, which needs no API key. The map is built offline, and the tiles are downloaded when it is displayed. The CARTO tiles, such as"CartoDB.Positron", need an API key, which these functions do not send, so they show a notice asking for one.- padding_km
A single positive number. The initial view shows at least this many kilometers on each side of the site; the default is 5.
- drive_time_min
A single number giving the drive time, in minutes, of the area to map, or
NULL(the default) for the longest drive time of the site iniso_sf. It must be one of the drive times iniso_sf.- variable_family
A string giving the kind of quantity that
variableis, as in theestimand_familycolumn ofcacs_run()results. It only chooses the ColorBrewer palette:"Greens"for"spatial_total"(a count; the default),"PuOr"for"median_proxy"(a median),"YlOrRd"for"area_weighted_scalar_proxy"(a per-person value), and"RdYlBu"for"derived_rate"(a rate).NAand unrecognized values give"YlGnBu", and"metadata_only"gives an error. The value is not checked againstvariable.- ...
Not used. Any argument given here is ignored.
Details
Clicking a tract shows the values that cacs_plot_site_intersection()
shows: GEOID, the coverage weight area_wt (the share of the tract's
area inside the drive-time area), and intersection_km2 (the area of
that part in square kilometers), with the variable code. It also shows
the tract's estimate, its margin of error (moe, the half-width of the
90 percent confidence interval published with the estimate), and the
coverage weight times the estimate, labeled "area_wt x estimate". For a
count, the products add up to the estimate that cacs_intersect_weight()
gives for the area, which is NA when any tract's estimate is missing.
For a median or a per-person value, that estimate is instead an average
of the tract estimates weighted by area shares (see
cacs_intersect_weight()), and the products do not add up to it.
The estimates are grouped into color classes by natural breaks when the
classInt package is installed and there are at least five different
estimates, and by pretty() otherwise. A tract with a missing estimate,
or with no row for variable in acs_sf, is gray.
With lat and lon instead of site_id, the rows of iso_sf are not
narrowed to one site. The drive time is then chosen among the drive times
of all the sites in iso_sf, and the area of every site for that drive
time is drawn, so a map of one area needs an iso_sf that holds the rows
of one site. cacs_plot_site_rates() and cacs_plot_site_pipeline()
differ: they map the site in sites_df nearest to the point.
See also
vignette("visual-walkthrough", package = "catchmentACS")
(https://joonho112.github.io/catchmentACS/articles/visual-walkthrough.html)
builds all four maps for one site, one section each.
Other maps of one site:
cacs_plot_site_intersection(),
cacs_plot_site_isochrone(),
cacs_plot_site_pipeline(),
cacs_plot_site_rates(),
format.cacs_site_plot_pipeline(),
print.cacs_site_plot_pipeline()
Examples
if (requireNamespace("leaflet", quietly = TRUE)) {
# Example data bundled with the package for one site in Birmingham,
# Alabama: a 10-minute drive-time area from the OSRM routing service,
# 2019-2023 ACS estimates for nearby tracts, and the cacs_run() result.
fx <- readRDS(system.file("extdata", "visual_walkthrough_fixture.rds",
package = "catchmentACS"))
# Median household income, a median
cacs_plot_site_weighted(site_id = "AL_BHM_01", iso_sf = fx$iso_sf,
tract_sf = fx$tract_sf, acs_sf = fx$acs_sf,
variable = "B19013_001",
variable_family = "median_proxy",
sites_df = fx$sites_df)
}