forked from beanumber/sds192-mp2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp2.Rmd
105 lines (88 loc) · 6.23 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
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
96
97
98
99
100
101
102
103
104
---
title: "Mini-Project 2"
author: "Natalia Iannucci, Hana Hirano, and Renee Wu"
date: "2019-03-24"
output:
html_document:
code_folding: hide
---
```{r, message = FALSE}
library(tidyverse)
library(ggthemes)
load("house_elections.rda")
load("candidates.rda")
load("committees.rda")
load("contributions.rda")
```
The power of negative gossip, rumors, and questionable information is strong. [A research study](http://science.sciencemag.org/content/332/6036/1446) suggests that it can even influence our visual processing, and can last in our memory for a longer period of time compared to positive or neutral information. In elections, it is common for some candidates to emphasize their opponents’ past mistakes, or spread false negative rumors about their opponents. An independent expenditure refers to money [spent by an individual, group, or political party, not in cooperation with the candidate](https://www.fec.gov/help-candidates-and-committees/making-independent-expenditures/). This is often spent on media such as TV advertisments or websites to support and oppose certain candidates.
In this mini-project, our goal is to use the data collected by the Federal Election Committee to show how expenditures differ between Democratic and Republican candidates; does one party consistently recieve expenditures supporting candiadtes as compared to opposing them? We also aim to examine how these differences bewteen the partys' expenditures differed between states. ^[https://github.com/niannucci/sds192-mp2]
First, we filtered two datasets (one on contrubutions and one on house elections information) for the variables that we will examine; the type of transaction (for or opposing a candidate), the political party that the transaction is in regards to, the transaction amount, and the state in which the transaction occurred.
```{r, message = FALSE}
contribution_data <- select(contributions, transaction_type, transaction_amt, cand_id, state)
house_election_data <- select(house_elections, fec_id, party, ge_winner)
```
Next we joined the two datasets to get the contributions and elections data together in one dataset.
```{r, message = FALSE}
contributions_to_elections <- contribution_data %>%
inner_join(house_election_data, by = c("cand_id" = "fec_id")) %>%
filter(transaction_type %in% c("24A", "24E")) %>%
filter(party %in% c("D", "R")) %>%
group_by(state)
```
We wrangled the data to look at total transactions per state to determine which states have the most overal transactions; we decided to use the ten states with the highest transaction amounts to use in our analysis, as this suggets sa greater polticial influence or importance in these states.
```{r, message = FALSE}
top_states <- contributions_to_elections %>%
group_by(state) %>%
summarize(total_transactions = sum(transaction_amt)) %>%
arrange(desc(total_transactions))
```
Next we filtered the dataset to only include the states with the top total transaction amounts.
```{r, message = FALSE}
top_contribution_states <- contributions_to_elections %>%
filter(state %in% c('VA', 'DC', 'MD', 'CA', 'IL', 'TX', 'PA', 'FL', 'NY', 'CO'))
```
We then graphed the transaction amounts for the top states according to if they were opposing or supporting a candidate, and which party they were for.
When the data is presented as a bar chart, the audience can easily compare the aomunts of transactions, as we mapped transction amount to the y-axis. As our purpose of this project was to illustrate the difference between Democrats and Republicans' expenditures, we decided that this data presentation would work the best, with political party mapped to the x-axis. We mapped color to whether the transaction was for opposing or supproting a candidate, with opposing bars filled in red due to the negative connotation of the color to make it easier to interpret.
```{r, message = FALSE}
ggplot(top_contribution_states, aes(x = party, y = transaction_amt)) +
geom_bar(stat = "identity", aes(fill = transaction_type), position = "dodge") +
scale_y_continuous(breaks = c(0, 400000, 800000, 1200000, 1600000, 2000000), labels = c(0, 0.4, 0.8, 1.2, 1.6, 2.0)) +
ggtitle("Independent Expenditure Transactions per Party") +
labs(subtitle = "For the top 10 States with the Highest Transaction Amounts") +
xlab("Political Party") +
ylab("Transaction Amount (in millions of dollars)") +
facet_wrap(~ state) +
scale_fill_manual(name = "Type of Transaction",label = c('Opposing Candidate', 'Supporting Candidate'), values = c('red', 'purple')) +
theme_stata() +
scale_color_stata() +
theme(axis.text.y=element_text(angle=0 ,hjust=0.5,vjust=1))
```
We calculated the total amount of money each party contributed to opposing a candidate, and found that almost independent expenditures by Republicans were almost $10 million more than Democrats regarding opposing the other candidates.
```{r, message = FALSE}
opposing_total <- function(party_name) {
contributions_to_elections %>%
filter(transaction_type == "24E") %>%
group_by(party) %>%
filter(party == party_name) %>%
summarize(total = sum(transaction_amt)) %>%
head(1)
}
opposing_total(party_name = "D")
opposing_total(party_name = "R")
```
We then calculated the total amount of money each party spent supporting a candidate, and found that in this case the total independent expenditures were much higher overall than for oppsing, but the amount was greater for Democrats than Republicans.
```{r, message = FALSE}
supporting_total <- function(party_name) {
contributions_to_elections %>%
filter(transaction_type == "24A") %>%
group_by(party) %>%
filter(party == party_name) %>%
summarize(total = sum(transaction_amt)) %>%
head(1)
}
supporting_total(party_name = "D")
supporting_total(party_name = "R")
```
This data tells us that the amount of money spent by each party varies significantly in each state, and how the money is spent (opposing a candidate or supporting another) is also different for each state.
From our analysis, we can conclude that political parties have different amounts of influence in different states, and thus expenditures differ based on if it is more beneficial to support a member of a party, or spend money opposing a member of a different party in that particular area.
> Word count: `r wordcountaddin::word_count()`