Skip to contents

Draws an interactive leaflet map of a site and the outline of its drive-time areas in iso_sf, merged into one. Clicking the site's point opens a pop-up that lists the site's values from run_result for the five rates in cacs_acs_default_rates.

Usage

cacs_plot_site_rates(
  site_id = NULL,
  lat = NULL,
  lon = NULL,
  site_name = NULL,
  iso_sf,
  run_result,
  sites_df = NULL,
  tiles = "OpenStreetMap",
  padding_km = 5,
  ...
)

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 site in sites_df nearest to the point is mapped, and a message of class catchmentACS_message_resolve_site gives its site_id and its distance from the point. If that site has no rows in run_result, the function stops with an error. If it is more than 5 km from the point, a warning of class catchmentACS_warning_resolve_site_distant is also given.

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.

run_result

A data frame of rates with the columns site_id, variable, estimate, moe, n_tracts_num, n_tracts_den, and moe_fallback, such as the long form of a cacs_run() result or the result of cacs_derive_rates(). The rows of the chosen site for the five rates are used, and there must be at least one.

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.

...

Not used. Any argument given here is ignored.

Value

A leaflet map (an HTML widget).

Details

For each rate, the pop-up shows the estimate and its margin of error (MOE, the half-width of a 90 percent confidence interval unless another level was used for run_result), both as proportions to four decimal places. It also shows the numbers of tracts combined for the numerator and for the denominator (n_tracts_num and n_tracts_den, filled in by cacs_derive_rates()), the MOE formula used (moe_formula_effective), and whether the chosen formula could not be used (moe_fallback). A rate with moe_fallback = TRUE also has an asterisk before its name: either the ratio formula was used in place of the proportion formula, or the denominator is zero and the rate is NA (see cacs_derive_rates()).

When run_result has rates for more than one drive time of the site, each rate is listed once for each drive time, and the pop-up does not show the drive time.

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"))
  # Clicking the site's point opens the pop-up with the five rates
  cacs_plot_site_rates(site_id = "AL_BHM_01", iso_sf = fx$iso_sf,
                       run_result = fx$run_result, sites_df = fx$sites_df)
}