Skip to content

Instantly share code, notes, and snippets.

@sysilviakim
Created November 2, 2021 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sysilviakim/b661be86f1773e101b803b7923be839f to your computer and use it in GitHub Desktop.
Save sysilviakim/b661be86f1773e101b803b7923be839f to your computer and use it in GitHub Desktop.
Presidential Years Turnout
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