Builds, for one site, the four maps that show step by step how the
package computes its estimates from American Community Survey (ACS) data,
and returns them in one list. The maps come from
cacs_plot_site_isochrone() (the site and its drive-time areas),
cacs_plot_site_intersection() (the census tracts that overlap one area,
shaded by coverage weight), cacs_plot_site_weighted() (one ACS variable
over those tracts), and cacs_plot_site_rates() (the five rates). A
tract's coverage weight is the share of its area inside the drive-time
area.
Usage
cacs_plot_site_pipeline(
site_id = NULL,
lat = NULL,
lon = NULL,
site_name = NULL,
iso_sf,
tract_sf,
acs_sf,
run_result,
sites_df = NULL,
variable = "B17001_002",
variable_family = "spatial_total",
tiles = "OpenStreetMap",
padding_km = 5,
drive_time_min = NULL,
...
)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. The nearest site insites_dfis found as incacs_plot_site_rates(), with one message, and used for all four maps.- 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.- run_result
A data frame of rates with the columns
site_id,variable,estimate,moe,n_tracts_num,n_tracts_den, andmoe_fallback, such as the long form of acacs_run()result or the result ofcacs_derive_rates(). The rows of the chosen site for the five rates are used, and there must be at least one.- 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.- 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.- 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 in the second and third maps, or
NULL(the default) for the longest drive time of the site iniso_sf. The first map draws all the areas of the site, and the fourth their outline.- ...
Passed to the four map functions, which do not use them.
Value
A list of class "cacs_site_plot_pipeline" with four leaflet
maps, isochrone, intersection, weighted, and rates, from the
four functions in that order. See print.cacs_site_plot_pipeline() for
what printing the list shows. The attributes site_id, lat, lon,
and name record the site used, and variable the variable of the
third map.
Details
The site is looked up once, before any map is built, and used for all
four. iso_sf, sites_df, tiles, padding_km, and ... are passed
to all four functions, tract_sf and drive_time_min to the second and
third, acs_sf, variable, and variable_family to the third, and
run_result to the fourth.
The function does not contact a routing service or the Census Bureau.
Its inputs are results computed beforehand: the drive-time areas by
cacs_isochrone(), the tract estimates by cacs_acs_prefetch(), and the
rates by cacs_run().
See also
The four maps are shown for one site in
vignette("visual-walkthrough", package = "catchmentACS")
(https://joonho112.github.io/catchmentACS/articles/visual-walkthrough.html).
Other maps of one site:
cacs_plot_site_intersection(),
cacs_plot_site_isochrone(),
cacs_plot_site_rates(),
cacs_plot_site_weighted(),
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"))
maps <- cacs_plot_site_pipeline(
site_id = "AL_BHM_01",
iso_sf = fx$iso_sf,
tract_sf = fx$tract_sf,
acs_sf = fx$acs_sf,
run_result = fx$run_result,
sites_df = fx$sites_df
)
# A summary of the four maps; no map is drawn
print(maps)
# The second map
maps$intersection
}
#>
#> ── catchmentACS site plot pipeline ─────────────────────────────────────────────
#> Site: AL_BHM_01 (Birmingham_Vulcan)
#> Variable (Stage 3): B17001_002
#>
#> ── 4 leaflet widgets returned ──
#>
#> • `x$isochrone` - Stage 1: site point + isochrone polygon
#> • `x$intersection` - Stage 2: tracts colored by area_wt
#> • `x$weighted` - Stage 3: tract choropleth on `B17001_002`
#> • `x$rates` - Stage 4: 5-rate popup summary
#> ℹ Show a map by typing its name, such as `x$isochrone`, in the console.
# Downloads ACS data with a Census API key and builds three areas on the
# public OSRM demo server with the osrm package; the server limits requests.
if (FALSE) { # \dontrun{
library(sf)
sites <- cacs_alabama_sites[1:3, ]
iso <- cacs_isochrone(sites, drive_times = 10)
acs <- cacs_acs_prefetch("AL")
out <- cacs_run(sites, state = "AL", drive_times = 10,
precomputed_isochrones = iso, acs = acs)
maps_live <- cacs_plot_site_pipeline(site_id = "AL_SITE_01", iso_sf = iso,
tract_sf = acs, acs_sf = acs,
run_result = out)
} # }