fec16 contains relational data from the Federal Election Commission website pertaining to candidates and committees for the United States 2015-2016 election cycle. Additionally, result of the 2016 general election and contribution data both from committees and individuals are included.
fec16
is hosted on GitHub and call be installed by running the
following:
devtools::install_github("ranawg/fec16")
library(fec16)
candidates
: all candidates registered with the FEC during the 2015-2016 election cyclecommittees
: all committees registered with the FEC during the 2015-2016 election cycleresults
: the results of the 2016 general presidential electionindividuals
: a sample of 5000 individual contributions to candidates/committees during the primary and general 2016 electionscommittee_contributions
: total contributions, aggregated by candidate, from committees
fec16
can be used to summarize data in order see how many candidates
are running for elections (in all offices) for the two major parties:
library(fec16)
library(tidyverse)
candidates %>%
filter(cand_pty_aff == "REP" | cand_pty_aff == "DEM") %>%
group_by(cand_pty_aff) %>%
summarise(size = n())
#> # A tibble: 2 x 2
#> cand_pty_aff size
#> <fct> <int>
#> 1 DEM 2242
#> 2 REP 2678
We can join any of the datasets using cand_id
. Each dataset with the
exception of the individuals
dataset contains a possible joining key:
cand_id
.
Here is an example of calculating how many candidates are in each of the two major parties: Democratic (DEM) and Republican (REP), based on their committee type:
cand_cmte <- candidates %>%
full_join(committees, by = "cand_id") %>%
filter(cand_pty_aff == "REP" | cand_pty_aff == "DEM") %>%
group_by(cand_pty_aff, committee_type) %>%
summarise(n = n()) %>%
drop_na(committee_type)
head(cand_cmte)
#> # A tibble: 6 x 3
#> # Groups: cand_pty_aff [109]
#> cand_pty_aff committee_type n
#> <fct> <fct> <int>
#> 1 DEM H 1540
#> 2 DEM P 147
#> 3 DEM S 278
#> 4 REP H 1715
#> 5 REP P 218
#> 6 REP S 399
And extending that to create a visualization to see the results easily.
ggplot(cand_cmte, aes(x = committee_type, y = n, fill = cand_pty_aff)) +
geom_col(position = "dodge") +
labs(title = "Bar Chart of Total Committees by Type and Party",
x = "Committee Type", y = "Count", fill = "Candidate Party Affiliation")