Created
November 2, 2021 19:57
-
-
Save sysilviakim/b661be86f1773e101b803b7923be839f to your computer and use it in GitHub Desktop.
Presidential Years Turnout
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) %>% | |
html_table() %>% | |
.[[1]] %>% | |
select(year = X1, vap = X6) %>% | |
filter(year != "Year") %>% | |
mutate( | |
year = as.numeric(year), | |
vap = as.numeric(gsub("%", "", vap)) | |
) | |
p <- ggplot(vap %>% filter(year >= 1920)) + | |
geom_line(aes(x = year, y = vap)) + | |
scale_x_continuous(breaks = seq(1920, 2020, by = 8)) + | |
xlab("Year") + | |
ylab("Turnout Based on VAP") + | |
scale_y_continuous(breaks = seq(45, 70, by = 2.5)) | |
p | |
pdf("turnout_millenium_2020.pdf", width = 5, height = 3.5) | |
pdf_default(p) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment