knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "##",
  fig.path =  "figure-markdown_github/")

uspoliticalextras

US political open source data & resources -- an R data package

A simple cache of US political data, collated from resources available on Git Hub & elsewhere. Big thanks to the folks at MIT Election Data and Science Lab, Civil Services, the Daily Kos & tidycensus for maintaining and making publically available these lovely resources!

I have simply aggregated these sources as an R package out of convenience, making minor adjustments in data structure and column names to facilitate joining among data sets.

Installation

library(devtools)
devtools::install_github("jaytimm/uspoliticalextras")
library(uspoliticalextras)
library(uspoliticalextras)
library(tidyverse)

Usage

Election returns

uspoliticalextras::uspol_medsl_returns_house_cd %>% select(year,GEOID, totalvotes:party)

Lawmaker biographical data

Lawmaker biographies via Civil Service. I have cleaned things up some, and eliminated some columns that are generally not useful to me. I have also joined icpsr values to facilitate joining with output from the Rvoteview package.

colnames(uspoliticalextras::uspol_csusa_house_bios)

File structure:

uspoliticalextras::uspol_csusa_house_bios

Equal-area polygons

names(uspol_dkos_equalarea_sf)

Congressional district demographic profiles

American Community Survey variables included in the profile include:

unique(uspoliticalextras::uspol_dems2017_house$variable)

File structure:

uspoliticalextras::uspol_dems2017_house

Voting patterns by congressional district

A table summarizing House election results (2016 & 2018) and Presidential elections results (2016) by congressional district. Facilitates some common House Rep cross-tabs. Full data set is available here. This blog post provides an R-based code-through detailing the compilation of the data set, and can serve as a convenient guide for locating vulnerable House Representatives come general elections in 2020. The table below, eg, lists the 31 Democrats in the 116th House representing districts won by 45 in 2016.

url1 <- 'https://raw.githubusercontent.com/jaytimm/uspoliticalextras/master/thirty-one-house-democrats/thirty-one-house-democrats.csv'

read.csv(url(url1))  %>%
  filter(Pres16_House18 == 'Trump | Democratic Party') %>%
  select(-house_rep_party, -Pres16, -Pres16_House18, -house_flip, -GEOID) %>%
  knitr::kable()


jaytimm/uspoliticalextras documentation built on March 17, 2020, 3:44 a.m.