Skip to contents

Draws an interactive leaflet map of one drive-time area of a site and the census tracts it overlaps. The part of each tract inside the area is shaded by the tract's coverage weight, labeled area_wt on the map: the share of the tract's area that lies inside the drive-time area. The color scale runs from 0 to 1 on every map, so a weight has the same color on all of them. The outline of the area and the site's point are drawn on top.

Usage

cacs_plot_site_intersection(
  site_id = NULL,
  lat = NULL,
  lon = NULL,
  site_name = NULL,
  iso_sf,
  tract_sf,
  sites_df = NULL,
  tiles = "OpenStreetMap",
  padding_km = 5,
  drive_time_min = NULL,
  ...
)

Arguments

site_id

A string giving the site_id of the site to map, used to find its point in sites_df and its drive-time areas in iso_sf.

lat, lon

Single numbers giving the latitude and longitude of a point in degrees (WGS 84), used when site_id is NULL. Both must be given. The point is marked at that location, and the areas of every site in iso_sf are used.

site_name

A string giving the name of the site, compared with the site_name column of sites_df including case, and used when site_id, lat, and lon are NULL. It must match one row.

iso_sf

An sf object of drive-time areas in EPSG:4326 (longitude and latitude), such as the result of cacs_isochrone(), with the columns site_id and drive_time_min.

tract_sf

An sf object of census tract polygons with a GEOID column, such as the result of cacs_acs_prefetch(). When a tract has several rows, as in that result (one for each variable), the first row is used.

sites_df

An sf object of site points in longitude and latitude with a site_id column, or NULL (the default) for cacs_alabama_sites. The bundled file legacy_2025_isochrones.rds uses the same site_id values for other places, so with its areas the default puts the point and the initial view far from them.

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 in iso_sf. It must be one of the drive times in iso_sf.

...

Not used. Any argument given here is ignored.

Value

A leaflet map (an HTML widget).

Details

cacs_intersect_weight() adds up counts with the same coverage weights, and combines medians and per-person values with area shares instead (each tract's share of the total overlap area). This function computes the overlaps itself from iso_sf and tract_sf, measuring areas in the equal-area projection EPSG:5070 as cacs_intersect_weight() does, but without its min_weight cut-off.

Clicking a tract shows its GEOID (the tract's Census identifier), its coverage weight, and the area of its part inside the drive-time area in square kilometers (intersection_km2).

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.

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"))
  cacs_plot_site_intersection(site_id = "AL_BHM_01", iso_sf = fx$iso_sf,
                              tract_sf = fx$tract_sf,
                              sites_df = fx$sites_df)
}