knitr::opts_chunk$set( collapse = TRUE, comment = "##", fig.path = "figure-markdown_github/")
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!
Election returns for House races (by congressional district), Senate races (by state) & presidential races (by state), made available by the MIT Election Data and Science Lab. 1976 - 2018.
Election returns for presidential races by congressional district, made available by the Daily Kos.
Lawmaker biographical details for the 115th & 116th congresses, made available by Civil Services project.
Equal-area shapefiles (as sf
objects) for US states & congressional districts, made available by the Daily Kos.
Demographic profiles for congressional districts based on ACS 2017 1-year estimates; accessed via tidycensus.
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.
library(devtools) devtools::install_github("jaytimm/uspoliticalextras") library(uspoliticalextras)
library(uspoliticalextras) library(tidyverse)
uspol_medsl_returns_house_cd
uspol_medsl_returns_senate_state
uspol_medsl_returns_pres_state
uspoliticalextras::uspol_medsl_returns_house_cd %>% select(year,GEOID, totalvotes:party)
uspol_dkos_returns_pres_cd
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
names(uspol_dkos_equalarea_sf)
American Community Survey variables included in the profile include:
unique(uspoliticalextras::uspol_dems2017_house$variable)
File structure:
uspoliticalextras::uspol_dems2017_house
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.