Skip to content

Instantly share code, notes, and snippets.

@lashlee
Created March 21, 2020 02:52
Show Gist options
  • Save lashlee/17ef79ba947cb4604bed31a110421c5a to your computer and use it in GitHub Desktop.
Save lashlee/17ef79ba947cb4604bed31a110421c5a to your computer and use it in GitHub Desktop.
I was curious who gave money to the Persist PAC!
# Setup -------------------------------------------------------------------
library(htmltab)
library(dplyr)
library(ggplot2)
library(knitr)
library(scales)
url <- 'https://docquery.fec.gov/cgi-bin/forms/C00739110/1391696//sa/ALL'
# Parse -------------------------------------------------------------------
raw_tab <- htmltab::htmltab(
doc = url
)
tab <-
raw_tab %>%
setNames(
c('name', 'address', 'occupation', 'memo', 'date', 'amount', 'total')
) %>%
mutate(
earmarked = is.na(memo),
date = as.Date(date, format = '%m/%d/%Y'),
amount = as.numeric(amount),
total = as.numeric(total)
) %>%
select(-memo) %>%
arrange(-total)
# Results -----------------------------------------------------------------
tab %>%
group_by(name, address) %>%
summarize(total = sum(amount)) %>%
ungroup() %>%
mutate(share = total / sum(total)) %>%
select(share, total, name, address, total) %>%
arrange(-share) %>%
mutate(share = percent(share, accuracy = .1), total = dollar(total)) %>%
kable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment