| Title: | Redistricting in Clean Tables |
|---|---|
| Description: | Provides a suite of tools to create tables that accompany maps. The tools create clean, informative tables for electoral outcomes, compactness, and other district-level quantities. Most tools are aimed at the redistricting context, but are broadly applicable to other electoral data. |
| Authors: | Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>), Cory McCartan [art] (ORCID: <https://orcid.org/0000-0002-6251-669X>) |
| Maintainer: | Christopher T. Kenny <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-06-01 09:33:35 UTC |
| Source: | https://github.com/christopherkenny/rict |
Color Columns with Partisan Scales
data_color_party(tab, columns = gt::everything(), ...)data_color_party(tab, columns = gt::everything(), ...)
tab |
A |
columns |
the columns to color with partisan colors |
... |
additional arguments passed on to |
A gt::gt
rict(wv_plans, 'cd_2020') |> data_color_party(columns = 'e_dvs')rict(wv_plans, 'cd_2020') |> data_color_party(columns = 'e_dvs')
gt
Extract data from a gt
gt_get_data(tab)gt_get_data(tab)
tab |
A |
rict(wv) |> gt_get_data()rict(wv) |> gt_get_data()
gt
Hide List Columns in gt
gt_hide_lists(tab)gt_hide_lists(tab)
tab |
A |
A gt::gt
wv |> gt::gt() |> gt_hide_lists()wv |> gt::gt() |> gt_hide_lists()
gt
Add Compactness Metric Plots to a gt
gt_plot_compactness( tab, shp, plan, measures = guess_comp(tab), height = 200, ... )gt_plot_compactness( tab, shp, plan, measures = guess_comp(tab), height = 200, ... )
tab |
A |
shp |
An |
plan |
A numeric vector with one entry for each precinct in |
measures |
A character vector indicating which measures to plot. Uses |
height |
height, in pixels, of each image. Default is 200. |
... |
additional arguments. Not currently passed on. |
A gt::gt
rict(wv_plans, 'cd_2020') |> gt_plot_compactness(wv, wv$cd_2020)rict(wv_plans, 'cd_2020') |> gt_plot_compactness(wv, wv$cd_2020)
sf Geometry Plots to a gt
Add sf Geometry Plots to a gt
gt_plot_sf(tab, name, height = 100, ...)gt_plot_sf(tab, name, height = 100, ...)
tab |
A |
name |
Name for |
height |
height, in pixels, of each image. Default is 100 |
... |
additional arguments passed on to |
A gt::gt
wv_dist <- wv |> dplyr::group_by(cd_2020) |> dplyr::summarize() gt::gt(wv_dist) |> gt_plot_sf()wv_dist <- wv |> dplyr::group_by(cd_2020) |> dplyr::summarize() gt::gt(wv_dist) |> gt_plot_sf()
Create Plots for Common Compactness Metrics
plot_compactness( shp, plan, measure = c("Polsby Popper", "Schwartzberg", "Reock", "Convex Hull", "Length Width", "Skew", "Box Reock"), fill_color = "deeppink" )plot_compactness( shp, plan, measure = c("Polsby Popper", "Schwartzberg", "Reock", "Convex Hull", "Length Width", "Skew", "Box Reock"), fill_color = "deeppink" )
shp |
An |
plan |
A numeric vector with one entry for each precinct in |
measure |
A character indicating which measure to plot. Default is |
fill_color |
hex or color name to fill the shape. A second entry can be provided to fill the background. |
list of ggplot2 plots
plot_compactness(wv, wv$cd_2020)plot_compactness(wv, wv$cd_2020)
Creates a formatted gt::gt table summarizing redistricting plans or maps.
rict(x, plan, ...)rict(x, plan, ...)
x |
A |
plan |
For |
... |
Additional arguments passed to methods. |
A gt::gt table
rict(wv) rict(wv_plans, 'cd_2020')rict(wv) rict(wv_plans, 'cd_2020')
Identifies neighboring precincts along a district boundary and displays them as adjacent pairs, with one row per pair of neighboring precincts from different districts.
rict_boundary(map, plan, seam, columns, adj_col = "adj", as_gt = TRUE)rict_boundary(map, plan, seam, columns, adj_col = "adj", as_gt = TRUE)
map |
A |
plan |
Column in |
seam |
Pair of districts in |
columns |
columns in |
adj_col |
Name of column in |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_boundary(map = wv, plan = wv$cd_2020, seam = c(1, 2), columns = pop)rict_boundary(map = wv, plan = wv$cd_2020, seam = c(1, 2), columns = pop)
Display compactness measures in a table
rict_compactness( map, plan, measures = list(comp_polsby = redistmetrics::comp_polsby, comp_schwartz = redistmetrics::comp_schwartz, comp_reock = redistmetrics::comp_reock, comp_ch = redistmetrics::comp_ch), as_gt = TRUE )rict_compactness( map, plan, measures = list(comp_polsby = redistmetrics::comp_polsby, comp_schwartz = redistmetrics::comp_schwartz, comp_reock = redistmetrics::comp_reock, comp_ch = redistmetrics::comp_ch), as_gt = TRUE )
map |
A |
plan |
Column in |
measures |
a list of named functions to score compactness |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_compactness(map = wv, plan = wv$cd_2020)rict_compactness(map = wv, plan = wv$cd_2020)
Display population data by administrative unit in a table
rict_component(map, plan, admin, as_gt = TRUE)rict_component(map, plan, admin, as_gt = TRUE)
map |
A |
plan |
Column in |
admin |
column names in |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_component(map = wv, plan = wv$cd_2020, admin = 'county')rict_component(map = wv, plan = wv$cd_2020, admin = 'county')
Display contiguity info in a table
rict_contiguity(map, plan, adj = NULL, adj_col = "adj", as_gt = TRUE)rict_contiguity(map, plan, adj = NULL, adj_col = "adj", as_gt = TRUE)
map |
A |
plan |
Column in |
adj |
An adjacency list (zero-indexed). If provided, used directly
instead of looking up |
adj_col |
Name of column in |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_contiguity(map = wv, plan = wv$cd_2020)rict_contiguity(map = wv, plan = wv$cd_2020)
Display demographic data in a table
rict_demographics(map, plan, normalize = TRUE, as_gt = TRUE)rict_demographics(map, plan, normalize = TRUE, as_gt = TRUE)
map |
A |
plan |
Column in |
normalize |
Logical. Should columns be normalized to percentages? Default: |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_demographics(map = wv, plan = wv$cd_2020)rict_demographics(map = wv, plan = wv$cd_2020)
Display electoral data in a table
rict_elections(map, plan, as_gt = TRUE)rict_elections(map, plan, as_gt = TRUE)
map |
A |
plan |
Column in |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_elections(map = wv, plan = wv$cd_2020)rict_elections(map = wv, plan = wv$cd_2020)
Display population parity in a table
rict_population(map, plan, as_gt = TRUE)rict_population(map, plan, as_gt = TRUE)
map |
A |
plan |
Column in |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_population(map = wv, plan = wv$cd_2020)rict_population(map = wv, plan = wv$cd_2020)
Display splits data in a table
rict_splits( map, plan, admin = NULL, subadmin = NULL, total = admin, multi = admin, as_gt = TRUE )rict_splits( map, plan, admin = NULL, subadmin = NULL, total = admin, multi = admin, as_gt = TRUE )
map |
A |
plan |
Column in |
admin |
column names in |
subadmin |
column names in |
total |
column names in |
multi |
column names in |
as_gt |
Logical. Should output be a |
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
rict_splits(map = wv, plan = wv$cd_2020, admin = 'state')rict_splits(map = wv, plan = wv$cd_2020, admin = 'state')
This file contains demographic, partisan, and geographic data for West Virginia at the county level.
redist_map object
GEOIDUS Census Geographic Identifier
NAMECounty name
stateState name
countyCounty name
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
cd_20102010 congressional district lines smoothed to the county level
cd_20202020 congressional district lines
pre_20_dem_bidvotes for Biden 2020, President (D)
pre_20_rep_truvotes for Trump 2020, President (R)
arv_20average Republican vote in 2020
adv_20average Democratic vote in 2020
nrvnormal Republican vote
ndvnormal Democratic vote
adjadjacency list, zero-indexed
sample_1random sampled plan from redist 50 states project
sample_2random sampled plan from redist 50 states project
sample_3random sampled plan from redist 50 states project
sample_4random sampled plan from redist 50 states project
sample_5random sampled plan from redist 50 states project
sample_6random sampled plan from redist 50 states project
sample_7random sampled plan from redist 50 states project
sample_8random sampled plan from redist 50 states project
sample_9random sampled plan from redist 50 states project
sample_10random sampled plan from redist 50 states project
sample_11random sampled plan from redist 50 states project
sample_12random sampled plan from redist 50 states project
geometrysf geometry
data(wv)data(wv)
This file contains 10 sampled plans from the ALARM Project 50 states project and the 2020 congressional plan for WV.
redist_plans object
drawdraw identifier
districtdistrict number
total_popTotal population
total_vapvoting age population
plan_devMaximum deviation from perfect population parity
comp_edgeFraction of Edges Kept compactness
comp_polsbyPolsby Popper compactness
pop_whiteWhite, non-Hispanic population
pop_blackBlack, non-Hispanic population
pop_hispHispanic 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
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_20_dem_bidvotes for Biden 2020, President (D)
pre_20_rep_truvotes for Trump 2020, President (R)
arv_20average Republican vote in 2020
adv_20average Democratic vote in 2020
nrvnormal Republican vote
ndvnormal Democratic vote
ndsharenormal Democratic share in the district
e_dvsexpected Democratic share in the district
pr_demproportion of districts where Democrats win reconstructed elections
e_demexpected number of Democratic seats
pbiaspartisan bias
egapefficiency gap
data(wv_plans)data(wv_plans)