-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathREADME.Rmd
95 lines (68 loc) · 3.16 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# fec16 <img src="data-raw/Sticker/hex_fec16.png" align="right" height=140/>
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
[![CRAN status](https://r-pkg.org/badges/version/fec16)](https://CRAN.R-project.org/package=fec16)
[![Travis-CI Build Status](https://travis-ci.org/ranawg/fec16.svg?branch=master)](https://travis-ci.org/ranawg/fec16)
<!-- badges: end -->
**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.
## Installation
`fec16` is hosted on GitHub and call be installed by running the following:
```{r, eval=FALSE}
devtools::install_github("ranawg/fec16")
```
```{r}
library(fec16)
```
## Data
- `candidates`: all candidates registered with the FEC during the 2015-2016 election cycle
- `committees`: all committees registered with the FEC during the 2015-2016 election cycle
- `results`: the results of the 2016 general presidential election
- `individuals`: a sample of 5000 individual contributions to candidates/committees during the primary and general 2016 elections
- `committee_contributions`: total contributions, aggregated by candidate, from committees
## Examples
### Data Wrangling
`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:
```{r example, message = FALSE}
library(fec16)
library(tidyverse)
candidates %>%
filter(cand_pty_aff == "REP" | cand_pty_aff == "DEM") %>%
group_by(cand_pty_aff) %>%
summarise(size = n())
```
#### Joining Data
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:
```{r message=FALSE, warning=FALSE}
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)
```
### Data Visualization
And extending that to create a visualization to see the results easily.
```{r message=FALSE, warning=FALSE}
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")
```
## Contributors
- [Irene Ryan](https://github.com/ireneryan)
- [Marium Tapal](https://github.com/mariumtapal)
- [Rana Gahwagy](https://github.com/ranawg)