redistio redistio website

redistio provides a point-and-click districting interface powered by Shiny and mapgl. For regular sf objects, it can be used to draw districts and export assignment files. For redist_map objects, algorithmic assistance is enabled for map drawing. It also includes an interactive adjacency graph editor via adj_editor().

Installation

You can install the development version of redistio from GitHub with:

pak::pak('christopherkenny/redistio')

Or from R-universe with:

install.packages('redistio', repos = c('https://christopherkenny.r-universe.dev', 'https://cloud.r-project.org'))

Example

The most basic application of redistio starts with an sf tibble and a column of district assignments.

library(redistio)

draw(dc, dc$ward)

Plans Browser and Comparisons

When working with redist_map objects and redist_plans, you can pass pre-computed plans to draw() for browsing and comparison. This enables two additional tabs in the app:

library(redistio)
library(redist)

map <- redist_map(dc, existing_plan = ward)
plans <- redist_smc(map, nsims = 100)

draw(map, init_plan = map$ward, plans = plans, plans_fn = add_plan_stats)

The plans_fn argument accepts a function that adds the current plan to the redist_plans object and computes summary statistics for comparison. The built-in add_plan_stats() function handles this automatically, computing statistics like population parity, compactness, partisan metrics, and administrative splits to match whatever columns are present in plans.

Adjacency Editor

redistio includes an interactive adjacency graph editor for fixing adjacency issues in your data (e.g., removing edges across rivers or adding edges for missing connections):

library(redistio)

adj_editor(dc, init_plan = dc$ward)

The editor lets you add or remove edges by clicking pairs of precincts, and provides an export tab with an edit log and reproducible code using geomander functions.

Configuration

Editor options

The editor can be configured primarily through redistio_options(). Some configurable options:

Data Dependent Options

Several data-based options may be configured inside draw():

More complex apps

These features allow for analyzing more complex maps, with live comparisons with simulations. For example, with the following code, you can have many more options:

library(redistio)
nj <- alarmdata::alarm_50state_map('NJ')
pl <- alarmdata::alarm_50state_plans('NJ')
draw(
  nj,
  init_plan = nj$cd_2020,
  palette = ggredist::ggredist$alaska,
  layers = list(County = 'county'),
  plans = pl,
  plans_fn = add_plan_stats
)