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
redist_plans
object.- ref_plan
An
integer
vector containing the reference plan, a block assignment file as atibble
ordata.frame
, or ansf
object where each row corresponds to a district.- map
A
redist_map
object. Only required if theredist_plans
object includes summary statistics.- name
A human-readable name for the reference plan. Defaults to the name of
ref_plan
. Ifref_plan
is atibble
ordata.frame
, it should be the name of the column ofref_plan
that identifies districts.- calc_polsby
A logical value indicating whether a Polsby-Popper compactness score should be calculated for the reference plan. Defaults to
FALSE
.- GEOID
character. If
ref_plan
is atibble
ordata.frame
, then it should correspond to the column ofref_plan
that identifies blockGEOID
s. Ifref_plan
is ansf
object, then it should correspond to the column ofref_plan
that identifies district numbers. Ignored whenref_plan
is numeric. Default is'GEOID'
.- year
the decade to request if passing a
tibble
toref_plan
, either2010
or2020
. Default is2020
.
Value
A modified redist_plans
object containing the reference plan. Includes summary statistics if the original redist_plans
object had them as well.
Examples
if (FALSE) { # Sys.getenv("DATAVERSE_KEY") != ""
# 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")
}