knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

These functions covers itemized data. Want to who has been donating large amounts of money to candidates? Where they live? What about how committees are spending money? Who are the outside spenders?

As shown in these examples, the tidyusafec suggested workflow is to pipe (%>%) the results of a function with the search_ prefix into a function with the get_ prefix.

All itemized data is tied to a committee_id.

get_itemized_contributions()

Itemized Contributions by Day

candidates <- search_candidates(election_year = 2018, office = "H", state = "MI", district = "06")

itemized_contributions <- candidates %>%
  filter(str_detect(name, "UPTON")) %>%
  get_itemized_contributions()

itemized_contributions %>%
  filter(is_individual == TRUE,
         is.na(memo_code)) %>%
  group_by(contribution_receipt_date) %>%
  summarise(total = sum(contribution_receipt_amount)) %>%
  mutate(year = lubridate::year(contribution_receipt_date),
         month = lubridate::month(contribution_receipt_date, label = TRUE),
         day = lubridate::day(contribution_receipt_date)) %>%
  ggplot() +
  geom_point(aes(x = day, y = reorder(month, desc(month)), size = total)) +
  facet_wrap(~year)
ggsave(filename = "itemized-contributions-example.png", width = 11, height = 5)

get_itemized_disbursements()

Itemized Disbursements by Category

candidates <- search_candidates(election_year = 2018, office = "H", state = "VA", district = "05")

itemized_disbursements <- candidates %>%
  filter(str_detect(name, "COCKBURN")) %>%
  get_itemized_disbursements()

itemized_disbursements %>%
  filter(is.na(memo_code)) %>%
  group_by(disbursement_purpose_category) %>%
  summarise(total = sum(disbursement_amount)) %>%
  ggplot() +
  geom_point(aes(y = disbursement_purpose_category, x = total))
ggsave(filename = "itemized-disbursements-example.png", width = 11, height = 5)



stephenholzman/tidyfec documentation built on Aug. 1, 2020, 9:35 p.m.