-
Notifications
You must be signed in to change notification settings - Fork 1
/
NumOfDailyContributionTrumpTimeSeries
72 lines (57 loc) · 3.26 KB
/
NumOfDailyContributionTrumpTimeSeries
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
# TIME SERIES TRUMP
install.packages("tidyverse")
library(tidyverse)
df <- read_csv("filter.csv")
newer <- df[,c(2, 35, 36, 37)]
newer$committee_name[newer$committee_name %in% "BIDEN FOR PRESIDENT"] <- "Joe Biden"
newer$committee_name[newer$committee_name %in% "DONALD J. TRUMP FOR PRESIDENT, INC."] <- "Donald Trump"
# View data class for each column that you wish to plot
committee <- newer %>%
filter(committee_name == "Donald Trump")
committeenew <- committee %>%
group_by(contribution_receipt_date) %>%
summarise(length_contribution_receipt_amount = length(contribution_receipt_amount))
committeenew$contribution_receipt_date <- as.Date(committeenew$contribution_receipt_date,
format = "%m/%d/%Y")
names(committeenew)[names(committeenew) == "contribution_receipt_date"] <- "date"
names(committeenew)[names(committeenew) == "length_contribution_receipt_amount"] <- "length"
subset(committeenew)
committeenew_after <- committeenew %>%
filter(date >= as.Date('2020-02-01') & date <= as.Date('2020-10-28'))
subset(committeenew_after)
library(ggplot2)
#HODP Theme
if (!require('dplyr')) install.packages('dplyr'); library(dplyr)
if (!require('ggplot2')) install.packages('ggplot2'); library(ggplot2)
if (!require('hrbrthemes')) install.packages('hrbrthemes'); library(hrbrthemes)
if (!require('magick')) install.packages('magick'); library(magick)
if (!require('plotly')) install.packages('plotly'); library(plotly)
logo <- image_read("logo.png")
# Legend: https://stackoverflow.com/questions/14622421/how-to-change-legend-title-in-ggplot
monochrome <- c('#760000', '#BE1E26', '#D84742', '#FF6B61', '#FF9586','#760000', '#BE1E26' )
primary <- c("#EE3838", "#FA9E1C", "#78C4D4", "#4B5973", "#E2DDDB", "#EE3838", "#FA9E1C")
sidebysidebarplot <- c("#ef3e3e", "#2c3e50")
theme_hodp <- function () {
theme_classic(base_size=12, base_family="Helvetica") %+replace%
theme(
panel.background = element_rect(fill="#F2F2F2", colour=NA),
plot.background = element_rect(fill="#F2F2F2", colour="#d3d3d3"),
legend.background = element_rect(fill="transparent", colour=NA),
legend.key = element_rect(fill="transparent", colour=NA),
plot.title = element_text(size=24, family="Helvetica", face = "bold", margin = margin(t = 0, r = 0, b = 10, l = 0)),
plot.subtitle = element_text(size=18, family="Helvetica", color="#717171", face = "italic", margin = margin(t = 0, r = 0, b = 10, l = 0)),
plot.caption = element_text(size=8, family="Helvetica", hjust = 1),
axis.text.x =element_text(size=10, family="Helvetica"),
axis.title.x =element_text(size=14, family="Helvetica", margin = margin(t = 10, r = 0, b = 0, l = 0), face = "bold"),
axis.title.y = element_text(margin = margin(t = 0, r = 10, b = 0, l = 0), size=14, family="Helvetica", angle=90, face ='bold'),
legend.title=element_text(size=10, family="Helvetica"),
legend.text=element_text(size=10, family="Helvetica"),
legend.position = "bottom",
axis.ticks = element_blank()
)
}
ggplot(committeenew_after, aes(x = date, y = length)) +
geom_bar(stat = "identity", fill = "red") +
scale_fill_manual(values = monochrome) +
xlab("Timeline from February 2020 to October 2020") +
ylab("Number of Daily Donations to Trump's Campaign")