-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
151 lines (106 loc) · 3.32 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
---
output:
md_document:
variant: markdown_github
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "##",
fig.path = "figure-markdown_github/")
```
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
source("/home/jtimm/pCloudDrive/GitHub/packages/render_toc.R")
```
# PresElectionResults
A data package for US Presidential election results.
> All build details are available [here](https://github.com/jaytimm/PresElectionResults/blob/master/builds.md), and are fully reproducible.
```{r echo=FALSE}
render_toc("/home/jtimm/pCloudDrive/GitHub/packages/PresElectionResults/README.Rmd",
toc_header_name = "PresElectionResults",
#base_level = NULL,
toc_depth = 3)
```
## Installation
```{r message=FALSE, warning=FALSE}
library(dplyr)
```
```{r eval=FALSE}
devtools::install_github("jaytimm/PresElectionResults")
```
## Presidential Election Results via Britannica
```{r}
PresElectionResults::pres_results |>
tail() |> knitr::kable()
```
## Presidential election results by county (2000-2020) via MIT Election Data and Science Lab (MEDSL)
```{r}
PresElectionResults::pres_by_county |>
head() |> knitr::kable()
```
## Presidential election results by congressional district (2020) via Daily Kos
```{r}
PresElectionResults::pres_by_cd |>
head() |> knitr::kable()
```
## Presidential election results by state (1864-) via Wikipedia
```{r}
PresElectionResults::pres_by_state |>
head() |> knitr::kable()
```
## Equal-area simple feature geometries via Daily Kos
```{r fig.height=6.5, message=FALSE, warning=FALSE}
# devtools::install_github("yutannihilation/ggsflabel")
library(sf)
library(ggplot2)
PresElectionResults::xsf_HexCDv30wm |>
ggplot() +
geom_sf(aes(fill = state),
color = 'white') +
geom_sf_text(data = PresElectionResults::xsf_HexSTv30wm,
aes(label = state_abbrev),
size = 3,
color='black') +
## scale_fill_distiller(palette = "RdBu", direction=-1) +
theme_minimal()+
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position = 'none') +
labs(title = "Equal-area US Congressional District geometry",
caption = "Source: DailyKos")
```
```{r fig.height=6.5, message=FALSE, warning=FALSE}
library(sf)
library(ggplot2)
PresElectionResults::xsf_TileOutv10 %>%
ggplot() +
geom_sf(aes(fill = state),
color = 'white') +
geom_sf(data = PresElectionResults::xsf_TileInv10,
fill = NA,
show.legend = F,
color="gray",
lwd=.5) +
geom_sf_text(data = PresElectionResults::xsf_TileInv10,
aes(label = state_abbrev),
size = 3,
color='black') +
##scale_fill_distiller(palette = "RdBu", direction=-1) +
theme_minimal()+
theme(axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position = 'none') +
labs(title = "Equal-area US State geometry",
caption = "Source: DailyKos")
```
## FRED Historical Population Data
```{r}
PresElectionResults::fred_pop_by_state |>
head()|>
knitr::kable()
```