| Title: | Interactive Redistricting |
|---|---|
| Description: | A point and click editor for districts built on 'shiny' and 'mapgl'. Users can draw districts and calculate standard redistricting metrics, like compactness or the number of administrative splits. Maps can be exported as assignment files or shapefiles, readable by most other redistricting software. |
| Authors: | Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>), Cory McCartan [aut] (ORCID: <https://orcid.org/0000-0002-6251-669X>) |
| Maintainer: | Christopher T. Kenny <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.0.9002 |
| Built: | 2026-05-15 16:14:06 UTC |
| Source: | https://github.com/christopherkenny/redistio |
Add summary statistics to plans
add_plan_stats(plans, ref_plan, map = NULL, name = NULL, ...)add_plan_stats(plans, ref_plan, map = NULL, name = NULL, ...)
plans |
a |
ref_plan |
an integer vector of district assignments |
map |
a |
name |
name for the reference plan. Defaults to |
... |
additional arguments (currently ignored) |
a redist_plans object with the reference plan added
dc_map <- redist::redist_map(dc, existing_plan = ward) plans <- redist::redist_smc(dc_map, nsims = 10) plans <- add_plan_stats(plans, dc_map$ward, map = dc_map, name = 'example')dc_map <- redist::redist_map(dc, existing_plan = ward) plans <- redist::redist_smc(dc_map, nsims = 10) plans <- add_plan_stats(plans, dc_map$ward, map = dc_map, name = 'example')
Interactive Adjacency Graph Editing
adj_editor( shp, adj = geomander::adjacency(shp), init_plan, palette = NULL, layers = NULL, hover_fn = hover_precinct, opts = redistio_options() )adj_editor( shp, adj = geomander::adjacency(shp), init_plan, palette = NULL, layers = NULL, hover_fn = hover_precinct, opts = redistio_options() )
shp |
an |
adj |
a zero-indexed adjacency graph |
init_plan |
plan to initialize coloring |
palette |
Color palette to fill shapes with. Default is |
layers |
Named list of |
hover_fn |
Function to generate tables for mouse hovering. Default is |
opts |
list of options. Default is |
Shiny app
if (interactive()) { adj_editor(dc, init_plan = dc$ward) adj_editor(dc, init_plan = dc$ward, layers = list(neighborhoods = 'adv_nbr')) }if (interactive()) { adj_editor(dc, init_plan = dc$ward) adj_editor(dc, init_plan = dc$ward, layers = list(neighborhoods = 'adv_nbr')) }
This file contains demographic, partisan, and geographic data for DC at the voting district level.
sf object
GEOID20US Census Geographic Identifier
statestate abbreviation
countycounty name
vtdvoting district identifier
poptotal population
pop_hispHispanic population
pop_whiteWhite, non-Hispanic population
pop_blackBlack, non-Hispanic population
pop_aianAmerican Indian and Alaskan Native, non-Hispanic population
pop_asianAsian, non-Hispanic population
pop_nhpiNative Hawaiian and Pacific Islander, non-Hispanic population
pop_otherOther, non-Hispanic population
pop_twoTwo or More Races, non-Hispanic population
vapvoting age population
vap_hispHispanic voting age population
vap_whiteWhite, non-Hispanic voting age population
vap_blackBlack, non-Hispanic voting age population
vap_aianAmerican Indian and Alaskan Native, non-Hispanic voting age population
vap_asianAsian, non-Hispanic voting age population
vap_nhpiNative Hawaiian and Pacific Islander, non-Hispanic voting age population
vap_otherOther, non-Hispanic voting age population
vap_twoTwo or More Races, non-Hispanic voting age population
pre_16_dem_clivotes for Clinton 2016, President (D)
pre_16_rep_truvotes for Trump 2016, President (R)
uss_18_dem_brovotes for Brown 2018, Shadow Senate (D)
atg_18_dem_racvotes for Karl Racine, Attorney General (D)
pre_20_dem_bidvotes for Biden 2020, President (D)
pre_20_rep_truvotes for Trump 2020, President (R)
uss_20_dem_strvotes for Strauss 2020, Shadow Senate (D)
uss_20_rep_weivotes for Weiss 2020, Shadow Senate (R)
arv_16average Republican vote in 2016
adv_16average Democratic vote in 2016
arv_18average Republican vote in 2018
adv_18average Democratic vote in 2016
arv_20average Republican vote in 2020
adv_20average Democratic vote in 2016
nrvnormal Republican vote
ndvnormal Democratic vote
geometrysf geometry
adv_nbrAdvisory Neighborhood names estimated to VTDs
ward2022 ward lines estimated to VTDs
data(dc)data(dc)
Interactive Plan Drawing
draw( shp, init_plan, ndists, palette = NULL, layers = NULL, pop_tol = 0.05, pop_col = "pop", adj_col = "adj", split_cols = guess_admins, elect_cols = guess_elections, demog_cols = guesstimate_demographics, plans = NULL, plans_fn = NULL, hover_fn = hover_precinct, opts = redistio_options() )draw( shp, init_plan, ndists, palette = NULL, layers = NULL, pop_tol = 0.05, pop_col = "pop", adj_col = "adj", split_cols = guess_admins, elect_cols = guess_elections, demog_cols = guesstimate_demographics, plans = NULL, plans_fn = NULL, hover_fn = hover_precinct, opts = redistio_options() )
shp |
an |
init_plan |
Plan to initialize with. |
ndists |
Number of districts to draw if |
palette |
Color palette to fill shapes with. Default is |
layers |
Named list of |
pop_tol |
the population tolerance. |
pop_col |
Name of column in |
adj_col |
Name of column in |
split_cols |
Names of column in |
elect_cols |
Names of column in |
demog_cols |
Names of column in |
plans |
a |
plans_fn |
a function to add a reference plan to |
hover_fn |
Function to generate tables for mouse hovering. Default is |
opts |
list of options. Default is |
Shiny app
if (interactive()) { draw(dc, dc$ward) draw(dc, dc$ward, layers = list(neighborhoods = 'adv_nbr')) }if (interactive()) { draw(dc, dc$ward) draw(dc, dc$ward, layers = list(neighborhoods = 'adv_nbr')) }
Guess which columns contain administrative units
guess_admins(shp)guess_admins(shp)
shp |
an |
a named list of types
guess_admins(dc)guess_admins(dc)
Guess which columns contain election data
guess_elections(shp)guess_elections(shp)
shp |
an |
a named list of columns
guess_elections(dc)guess_elections(dc)
Guess and estimate which columns contain demographic data
guesstimate_demographics(shp)guesstimate_demographics(shp)
shp |
an |
a named list of columns
guesstimate_demographics(dc)guesstimate_demographics(dc)
tibble of precinct statsCreate a tibble of precinct stats
hover_precinct(shp, ...)hover_precinct(shp, ...)
shp |
a tibble::tibble with precinct stats |
... |
named tidyselections |
A tibble::tibble with columns group, rowname, and one column
per precinct (V1, V2, ...). Groups are labeled with human-readable
names (e.g. "Total Population", "Voting Age Population").
hover_precinct(dc, pop = dplyr::starts_with('pop'), vap = dplyr::starts_with('vap'))hover_precinct(dc, pop = dplyr::starts_with('pop'), vap = dplyr::starts_with('vap'))
redistio
Set options for redistio
redistio_options( theme = "flatly", panels = c("elections", "demographics", "integrity", "algorithms", "plans", "comparisons"), select_color = "purple", border_color = "#000000", palette_pop = "Purples", palette_pct = "PuOr", palette_party = ggredist::ggredist$partisan, map_tiles = mapgl::carto_style("voyager"), leaflet_height = "91vh", crs = 4326, na_color = "#0000", layer_weight = 1.5, layer_color = "#000000", locked_districts = NULL, use_algorithms = TRUE, alg_max_districts = 3, alg_max_sims = 100, use_plans = TRUE, use_comparisons = TRUE, use_planscore = TRUE, save_assignment_path = "redistio.csv", save_shape_path = "redistio.geojson", debounce = 150, projection = "mercator", plot_theme = ggplot2::theme_bw(), plot_geom = "boxplot", plot_ref_geom = NULL, ... )redistio_options( theme = "flatly", panels = c("elections", "demographics", "integrity", "algorithms", "plans", "comparisons"), select_color = "purple", border_color = "#000000", palette_pop = "Purples", palette_pct = "PuOr", palette_party = ggredist::ggredist$partisan, map_tiles = mapgl::carto_style("voyager"), leaflet_height = "91vh", crs = 4326, na_color = "#0000", layer_weight = 1.5, layer_color = "#000000", locked_districts = NULL, use_algorithms = TRUE, alg_max_districts = 3, alg_max_sims = 100, use_plans = TRUE, use_comparisons = TRUE, use_planscore = TRUE, save_assignment_path = "redistio.csv", save_shape_path = "redistio.geojson", debounce = 150, projection = "mercator", plot_theme = ggplot2::theme_bw(), plot_geom = "boxplot", plot_ref_geom = NULL, ... )
theme |
a name of a bootswatch preset theme or other |
panels |
which panels to display in the app, |
select_color |
a color to use for highlighting selected districts |
border_color |
a color to use for precinct borders in the map |
palette_pop |
a color palette to use for whole people. Defaults to
|
palette_pct |
a color palette to use for percentages of people. Defaults
to |
palette_party |
a color palette to use for parties |
map_tiles |
a tileset to use for the map background, from |
leaflet_height |
height to pass to |
crs |
a coordinate reference system to use in |
na_color |
a color to use for unassigned precincts |
layer_weight |
a stroke width to use for layers in |
layer_color |
colors to use for layers in |
locked_districts |
districts to lock on app start to stop edits |
use_algorithms |
whether to use redistricting simulation algorithms |
alg_max_districts |
maximum number of districts to use in algorithms |
alg_max_sims |
maximum number of simulations to use in algorithms |
use_plans |
whether to show the plans browser tab when |
use_comparisons |
whether to show the comparisons tab when |
use_planscore |
whether to use PlanScore to evaluate plans |
save_assignment_path |
Output path to save assignment file to. |
save_shape_path |
Output path to save shapefile to. |
debounce |
Number of milliseconds to debounce map hover events. Defaults to 150. |
projection |
Maplibre projection to use. Default is |
plot_theme |
a ggplot2 theme to apply to comparison plots. Default is
|
plot_geom |
a geom to use for district-level comparison plots, passed
to the |
plot_ref_geom |
a geom function to use for the reference plan overlay
in district-level comparison plots, passed to the |
... |
additional arguments (currently ignored) |
a list
redistio_options()redistio_options()