This file contains hidden or 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
# Swirl and swirl lessons installation guide | |
install.packages("swirl") | |
library(swirl) # load the swirl package | |
## To start a swirl lesson, | |
## Type in `swirl()` | |
## These courses contain some useful lessons to do via swirl. | |
install_course_github("kosukeimai", "qss-swirl") | |
install_course("R Programming") |
This file contains hidden or 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) %>% |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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") %>% |
NewerOlder