This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(magrittr) | |
if (!require("wru")) { | |
devtools::install_github("sysilviakim/wru") | |
} | |
library(wru) | |
census_2010_age_sex <- census_2010_sex <- census_2010_age <- census_2010 <- | |
c(state.abb, "DC") %>% set_names(., .) %>% map(~list()) | |
key <- "CENSUS_KEY" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rvest) | |
library(jsonlite) | |
library(xtable) | |
## How many Electoral College electors per state? ============================== | |
## Page as is for Sep 1, 2020 | |
url_270 <- "https://www.270towin.com" | |
electors <- read_html(url_270) %>% | |
html_nodes("script") %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Library and data import ====================================================== | |
library(tidyverse) | |
library(scales) | |
library(ggrepel) | |
library(Kmisc) # devtools::install_github("sysilviakim/Kmisc") | |
options(digits = 5, scipen = 999) | |
# MEDSL Data: U.S. President 1976–2016 | |
# https://doi.org/10.7910/DVN/42MVDX | |
# This data file contains constituency (state_po-level) returns for elections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renv::init() | |
install.packages("devtools") | |
install.packages("remotes") | |
install.packages("colorspace") | |
library(remotes) | |
install_github( | |
"sysilviakim/Kmisc", INSTALL_opts = c("--no-multiarch"), dependencies = TRUE | |
) | |
Kmisc::proj_skeleton() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(ggplot2) | |
library(ggridges) | |
library(Kmisc) | |
# Brookings Party Unity Votes ================================================== | |
url <- | |
"https://www.brookings.edu/wp-content/uploads/2017/01/vitalstats_ch8_tbl3.csv" | |
df <- read.csv(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
set.seed(100) | |
df <- tibble( | |
n = seq(1e5), | |
x = rbinom(1e5, 1, 0.5), | |
y = cumsum(x) / n | |
) | |
## In base R, plot(df$n, df$y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(readxl) | |
library(janitor) | |
download.file( | |
url = | |
"https://www2.census.gov/programs-surveys/cps/tables/p20/585/table04a.xlsx", | |
destfile = "turnout2020.xlsx", | |
mode = "wb" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rvest) | |
library(Kmisc) | |
url <- paste0( | |
"https://www.presidency.ucsb.edu/statistics/data/", | |
"voter-turnout-in-presidential-elections" | |
) | |
vap <- read_html(url) %>% |
OlderNewer