| Title: | Redistricting in Clean Tables |
| Version: | 0.0.1 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | cli, dplyr, geomander, geos, ggplot2, gt, purrr, redist, redistmetrics, rlang, sf, stringr, tibble |
| Depends: | R (≥ 4.1.0) |
| LazyData: | true |
| Suggests: | knitr, rmarkdown, spelling, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| URL: | http://christophertkenny.com/rict/, https://github.com/christopherkenny/rict |
| BugReports: | https://github.com/christopherkenny/rict/issues |
| Language: | en-US |
| NeedsCompilation: | no |
| Packaged: | 2026-02-27 16:43:09 UTC; chris |
| Author: | Christopher T. Kenny
|
| Maintainer: | Christopher T. Kenny <ctkenny@proton.me> |
| Repository: | CRAN |
| Date/Publication: | 2026-03-04 10:20:02 UTC |
rict: 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.
Author(s)
Maintainer: Christopher T. Kenny ctkenny@proton.me (ORCID)
See Also
Useful links:
Report bugs at https://github.com/christopherkenny/rict/issues
Color Columns with Partisan Scales
Description
Color Columns with Partisan Scales
Usage
data_color_party(tab, columns = gt::everything(), ...)
Arguments
tab |
A |
columns |
the columns to color with partisan colors |
... |
additional arguments passed on to |
Value
A gt::gt
Examples
rict(wv_plans, 'cd_2020') |>
data_color_party(columns = 'e_dvs')
Extract data from a gt
Description
Extract data from a gt
Usage
gt_get_data(tab)
Arguments
tab |
A |
Value
Examples
rict(wv) |> gt_get_data()
Hide List Columns in gt
Description
Hide List Columns in gt
Usage
gt_hide_lists(tab)
Arguments
tab |
A |
Value
A gt::gt
Examples
wv |>
gt::gt() |>
gt_hide_lists()
Add Compactness Metric Plots to a gt
Description
Add Compactness Metric Plots to a gt
Usage
gt_plot_compactness(
tab,
shp,
plan,
measures = guess_comp(tab),
height = 200,
...
)
Arguments
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. |
Value
A gt::gt
Examples
rict(wv_plans, 'cd_2020') |>
gt_plot_compactness(wv, wv$cd_2020)
Add sf Geometry Plots to a gt
Description
Add sf Geometry Plots to a gt
Usage
gt_plot_sf(tab, name, height = 100, ...)
Arguments
tab |
A |
name |
Name for |
height |
height, in pixels, of each image. Default is 100 |
... |
additional arguments passed on to |
Value
A gt::gt
Examples
wv_dist <- wv |>
dplyr::group_by(cd_2020) |>
dplyr::summarize()
gt::gt(wv_dist) |> gt_plot_sf()
Create Plots for Common Compactness Metrics
Description
Create Plots for Common Compactness Metrics
Usage
plot_compactness(
shp,
plan,
measure = c("Polsby Popper", "Schwartzberg", "Reock", "Convex Hull", "Length Width",
"Skew", "Box Reock"),
fill_color = "deeppink"
)
Arguments
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. |
Value
list of ggplot2 plots
Examples
plot_compactness(wv, wv$cd_2020)
Create a Summary Table from Redistricting Data
Description
Creates a formatted gt::gt table summarizing redistricting plans or maps.
Usage
rict(x, plan, ...)
Arguments
x |
A |
plan |
For |
... |
Additional arguments passed to methods. |
Value
A gt::gt table
Examples
rict(wv)
rict(wv_plans, 'cd_2020')
Display boundary information in a table
Description
Identifies neighboring precincts along a district boundary and displays them as adjacent pairs, with one row per pair of neighboring precincts from different districts.
Usage
rict_boundary(map, plan, seam, columns, adj_col = "adj", as_gt = TRUE)
Arguments
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 |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_boundary(map = wv, plan = wv$cd_2020, seam = c(1, 2), columns = pop)
Display compactness measures in a table
Description
Display compactness measures in a table
Usage
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
)
Arguments
map |
A |
plan |
Column in |
measures |
a list of named functions to score compactness |
as_gt |
Logical. Should output be a |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_compactness(map = wv, plan = wv$cd_2020)
Display population data by administrative unit in a table
Description
Display population data by administrative unit in a table
Usage
rict_component(map, plan, admin, as_gt = TRUE)
Arguments
map |
A |
plan |
Column in |
admin |
column names in |
as_gt |
Logical. Should output be a |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_component(map = wv, plan = wv$cd_2020, admin = 'county')
Display contiguity info in a table
Description
Display contiguity info in a table
Usage
rict_contiguity(map, plan, adj = NULL, adj_col = "adj", as_gt = TRUE)
Arguments
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 |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_contiguity(map = wv, plan = wv$cd_2020)
Display demographic data in a table
Description
Display demographic data in a table
Usage
rict_demographics(map, plan, normalize = TRUE, as_gt = TRUE)
Arguments
map |
A |
plan |
Column in |
normalize |
Logical. Should columns be normalized to percentages? Default: |
as_gt |
Logical. Should output be a |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_demographics(map = wv, plan = wv$cd_2020)
Display electoral data in a table
Description
Display electoral data in a table
Usage
rict_elections(map, plan, as_gt = TRUE)
Arguments
map |
A |
plan |
Column in |
as_gt |
Logical. Should output be a |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_elections(map = wv, plan = wv$cd_2020)
Display population parity in a table
Description
Display population parity in a table
Usage
rict_population(map, plan, as_gt = TRUE)
Arguments
map |
A |
plan |
Column in |
as_gt |
Logical. Should output be a |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_population(map = wv, plan = wv$cd_2020)
Display splits data in a table
Description
Display splits data in a table
Usage
rict_splits(
map,
plan,
admin = NULL,
subadmin = NULL,
total = admin,
multi = admin,
as_gt = TRUE
)
Arguments
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 |
Value
a gt::gt_tbl if as_gt = TRUE, otherwise a tibble::tibble
Examples
rict_splits(map = wv, plan = wv$cd_2020, admin = 'state')
West Virginia Geographic Data
Description
This file contains demographic, partisan, and geographic data for West Virginia at the county level.
Format
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
redist50 states projectsample_2random sampled plan from
redist50 states projectsample_3random sampled plan from
redist50 states projectsample_4random sampled plan from
redist50 states projectsample_5random sampled plan from
redist50 states projectsample_6random sampled plan from
redist50 states projectsample_7random sampled plan from
redist50 states projectsample_8random sampled plan from
redist50 states projectsample_9random sampled plan from
redist50 states projectsample_10random sampled plan from
redist50 states projectsample_11random sampled plan from
redist50 states projectsample_12random sampled plan from
redist50 states projectgeometrysf geometry
Examples
data(wv)
West Virginia Redistricting Plans
Description
This file contains 10 sampled plans from the ALARM Project 50 states project and the 2020 congressional plan for WV.
Format
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
Examples
data(wv_plans)