generated from jtr13/bookdown-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-race.Rmd
134 lines (110 loc) · 5.76 KB
/
03-race.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Project 2024
<p>
Project 2024 is about President Biden and Donald Trump re-match from the 2020 election in which Biden won 51%-47% nationally with 306 electoral votes.
</p>
## National Polling
<p>
Head to head national polling is neck and neck between Biden and Trump. The polls shows Trump doing well with black voters by doubling his 10% from 2020 while increasing support from hispanic and under 35 voters.
</p>
```{r biden_vs_trump,echo = FALSE, results = 'hide', warning = FALSE,message=FALSE, fig.height=5,fig.width=8,fig.align='center', fig.cap="National polling results",dpi=720}
library(cowplot)
library(ggplot2)
library(lubridate)
library(tidyverse)
library(readxl)
library(gridExtra)
ballots <- read_excel("~/ballots.xltx", sheet = "H2H")
ballots$end_date<-mdy(ballots$end_date)
h_h<-ggplot(ballots, mapping = aes(x=end_date, y=Two_Way,color=candidate_name))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=0.7, se=FALSE, lwd=2) +
scale_colour_manual(values = c('red','blue'))+
labs(title = 'Biden vs Trump',x=' ',caption = " ",
y='%Percentage%', colour=' ')+
theme_bw()+
theme(legend.position = 'none') +
theme(plot.title = element_text(face = "bold"),axis.text = element_text(face = "bold"))
blk<-ggplot(ballots, mapping = aes(x=end_date, y=Two_Way_BLK,color=candidate_name))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=0.7, se=FALSE, lwd=2) +
scale_colour_manual(values = c('red','blue'))+
labs(title = 'Black Voters',x='',caption = " ",
y=' ', colour=' ')+
theme_bw()+
theme(legend.position = 'none') +
theme(plot.title = element_text(face = "bold",hjust = 1),axis.text = element_text(face = "bold"))
hsp<-ggplot(ballots, mapping = aes(x=end_date, y=Two_Way_HISP,color=candidate_name))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=0.7, se=FALSE, lwd=2) +
scale_colour_manual(values = c('red','blue'))+
labs(title = 'Hispanic Voters',x=' ',caption = " ",
y='%Percentage%', colour=' ')+
theme_bw()+
theme(legend.position = 'bottom')+
theme(plot.title = element_text(face = "bold"),axis.text = element_text(face = "bold"))
u35<-ggplot(ballots, mapping = aes(x=end_date, y=Two_Way_U35,color=candidate_name))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=1, se=FALSE, lwd=2) +
scale_colour_manual(values = c('red','blue'))+
labs(title = 'Under 35 Voters',x=' ',caption = "sources:538.com\njamesstats.github.io/blog",
y=' ', colour='Key')+
theme_bw()+
theme(legend.position = 'bottom')+
theme(plot.title = element_text(face = "bold",hjust = 1),
plot.caption = element_text(face = 'italic'),axis.text = element_text(face = 'bold'))
plist<-list(h_h,blk,hsp,u35)
grid.arrange(grobs = plist, ncol = 2) ## display plot
```
## Third Party Spoilers?
<p>
Some of the national polling also includes third party candidates with Robert F.Kennedy Jr being the most known because of the last name. Jill Stein is also running again after spoiling for Hillary Clinton in 2016. It's yet to be seen if they will maintain their support in November but the re-match of Biden and Trump is creating a space for them.
</p>
```{r biden_trump_3rd_party,echo = FALSE, results = 'hide', warning = FALSE,message=FALSE, fig.height=5,fig.width=8,fig.align='center', fig.cap="National polling results",dpi=720}
library(cowplot)
library(ggplot2)
library(lubridate)
library(tidyverse)
library(readxl)
library(gridExtra)
ballot_3 <- read_excel("~/ballots.xltx", sheet = "3_way")
ballot_3$end_date<-mdy(ballot_3$end_date)
h3h<-ggplot(ballot_3, mapping = aes(x=end_date, y=Third_Party,color=answer))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=1, se=FALSE, lwd=2) +
scale_colour_manual(values = c('blue','yellow',"green","red","purple"))+
labs(title = 'Biden & Trump vs Third Party ',x=' ',caption = " ",
y='%Percentage%', colour=' ')+
theme_bw()+
theme(legend.position = 'none') +
theme(plot.title = element_text(face = "bold"),axis.text = element_text(face = "bold"))
blk_3<-ggplot(ballot_3, mapping = aes(x=end_date, y=Third_Party_BLK,color=answer))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span= 1, se=FALSE, lwd=2) +
scale_colour_manual(values = c('blue','yellow',"green","red","purple"))+
labs(title = 'Black Voters',x='',caption = " ",
y=' ', colour=' ')+
theme_bw()+
theme(legend.position = 'none') +
theme(plot.title = element_text(face = "bold",hjust = 1),axis.text = element_text(face = "bold"))
hsp_3<-ggplot(ballot_3, mapping = aes(x=end_date, y=Third_Party_HISP,color=answer))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=1, se=FALSE, lwd=2) +
scale_colour_manual(values = c('blue','yellow',"green","red","purple"))+
labs(title = 'Hispanic Voters',x=' ',caption = " ",
y='%Percentage%', colour=' ')+
theme_bw()+
theme(legend.position = 'bottom')+
theme(plot.title = element_text(face = "bold"),axis.text = element_text(face = "bold"))
u_35<-ggplot(ballot_3, mapping = aes(x=end_date, y=Third_Party_U35,color=answer))+
geom_point(alpha=1/10,size=5) +
geom_smooth(method = 'loess', formula = 'y~x',span=1, se=FALSE, lwd=2) +
scale_colour_manual(values = c('blue','yellow',"green","red","purple"))+
labs(title = 'Under 35 Voters',x=' ',caption = "sources:538.com\njamesstats.github.io/blog",
y=' ', colour=' ')+
theme_bw()+
theme(legend.position = 'none')+
theme(plot.title = element_text(face = "bold",hjust = 1),
plot.caption = element_text(face = 'italic'),axis.text = element_text(face = 'bold'))
plist<-list(h3h,blk_3,hsp_3,u_35)
grid.arrange(grobs = plist, ncol = 2) ## display plot
```