alarm_add_plan {alarmdata} | R Documentation |
Add a reference plan to a set of plans
Description
Facilitates comparing an existing (i.e., non-simulated) redistricting plan to a set of simulated plans.
Usage
alarm_add_plan(
plans,
ref_plan,
map = NULL,
name = NULL,
calc_polsby = FALSE,
GEOID = "GEOID",
year = 2020
)
Arguments
plans |
A |
ref_plan |
An integer vector containing the reference plan or a block assignment file as a |
map |
A |
name |
A human-readable name for the reference plan. Defaults to the name of |
calc_polsby |
A logical value indicating whether a Polsby-Popper compactness score should be calculated for the reference plan. Defaults to |
GEOID |
character. Ignored unless |
year |
the decade to request if passing a |
Value
A modified redist_plans
object containing the reference plan. Includes summary statistics if the original redist_plans
object had them as well.
Examples
# requires Harvard Dataverse API key
map <- alarm_50state_map("WY")
pl <- alarm_50state_plans("WY")
pl_new <- alarm_add_plan(pl, ref_plan = c(1), map, name = "example")
# download and load a comparison plan
url <- paste0("https://github.com/PlanScore/Redistrict2020/raw/main/files/",
"NM-2021-10/Congressional_Concept_A.zip")
tf <- tempfile(fileext = ".zip")
utils::download.file(url, tf)
utils::unzip(tf, exdir = dirname(tf))
baf <- readr::read_csv(file = paste0(dirname(tf), "/Congressional Concept A.csv"),
col_types = "ci")
names(baf) <- c("GEOID", "concept_a")
# Add it to the plans object
map_nm <- alarm_50state_map("NM")
plans_nm <- alarm_50state_plans("NM", stats = FALSE)
alarm_add_plan(plans_nm, baf, map = map_nm, name = "concept_a")