forked from beanumber/sds192-mp2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp2.Rmd
54 lines (47 loc) · 1.11 KB
/
mp2.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
---
title: "Mini-Project 2"
author: "Sunnie Ning and Ayumi Mizuno"
date: "October 31, 2017"
output: html_document
---
#Can you see this Sunnie??? :D
## Loading the data
```{r, include=FALSE}
load("house_elections.rda")
load("candidates.rda")
load("committees.rda")
load("contributions.rda")
load("individuals.rda")
```
```{r}
library(tidyverse)
library(ggplot2)
```
```{r}
glimpse(contributions)
```
```{r}
candidatespac<-candidates %>%
select(cand_id,cand_name,cand_party_affiliation)
committeespac<-committees %>%
select(cmte_id,cmte_name,cmte_party_affiliation,connected_org_name)
```
```{r}
pac<-contributions %>%
filter(entity_type =="PAC") %>%
select(cmte_id,transaction_amt,transaction_pgi,cand_id) %>%
left_join(candidatespac, by=('cand_id' = 'cand_id')) %>%
left_join(committeespac, by = ("cmte_id" = "cmte_id"))
```
```{r}
pac1<-pac %>%
group_by(cmte_name,cand_name) %>%
summarize(transactionsum = sum(transaction_amt)) %>%
arrange(desc(transactionsum)) %>%
head(10)
```
```{r}
p<-ggplot(pac1,aes(x = cmte_name, y =transactionsum))+
geom_bar(stat= "identity",aes(fill= cand_name))
p
```