The R code below can replicate this chart. You can get help installing R here. You can get help with the tidyusafec data retreival package here.
# Load R packages
library(tidyusafec)
library(tidyverse)
# Get Data
candidates <- search_candidates(
office = 'H',
election_year = '2018',
district = '06',
state = 'IN',
unnest_committees = FALSE
)
candidate_totals <- candidates %>%
get_candidate_totals()
# Wrangle Data
chart_data <- candidate_totals %>%
filter(type_of_funds %in% tidyusafec_filters$candidate_totals$type_of_funds$top_level,
last_report_year == '2018') %>%
mutate(type_of_funds = type_of_funds %>% str_replace_all('_',' ') %>% str_to_title(),
name = fct_reorder(name, -desc(amount)))
# Visualize Data
ggplot(data = chart_data) +
geom_bar(aes(x = name, y = amount, fill = party), stat = 'identity') +
coord_flip() +
facet_wrap(~type_of_funds, labeller = label_wrap_gen(width = 10)) +
scale_fill_manual(values = c('DEM' = '#2c4d82', 'REP' = '#8e1b1b', 'IND' = '#a3a3a3', 'GRE' = '#1c561d', 'LIB' = '#afac3d','NNE' = '#0A0A0A')) +
scale_y_continuous(labels = scales::dollar) +
theme_bw() +
theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust = .5)) +
labs(
title = 'Indiana Congressional District 06 Race - 2018',
subtitle = 'Financial Summary',
x = '',
y = '',
fill = 'Party',
caption = paste0('Source: FEC. Data retreived on ', Sys.Date(), ', created by @StephenHolz')
)