-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGDP_and_Regime.Rmd
200 lines (152 loc) · 5.62 KB
/
GDP_and_Regime.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
---
title: "GDP and Regime"
author: "Cian Stryker"
date: "5/13/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(readxl)
library(gt)
library(cowplot)
library(png)
library(scales)
library(ggthemes)
library(janitor)
library(countrycode)
library(tidyverse)
```
```{r GDP Cleaning}
GDP <- read_csv("Data/GDP_World_Bank.csv", col_types = cols(
.default = col_double(),
`Country Name` = col_character(),
`Country Code` = col_character(),
`2019` = col_logical()
))
GDP <- GDP[, -c(2, 26)]
GDP <- GDP %>%
pivot_longer(-`Country Name`,
names_to = "year",
values_to = "GDP") %>%
clean_names()
GDP$country_name <- countrycode(GDP$country_name, "country.name", "country.name")
GDP$country_code = GDP$country_name
GDP$country_code <- countrycode(GDP$country_code, "country.name", "iso2c")
GDP<- GDP[c(1, 4, 2, 3)]
```
```{r Regime, warning = FALSE}
Freedom_House <- read_excel("Data/Freedom_House.xlsx")
FH <- Freedom_House
FH$year <- FH$Edition
FH$country_name <- countrycode(FH$`Country/Territory`, "country.name", "country.name")
FH$country_code = FH$country_name
FH$country_code <- countrycode(FH$country_code, "country.name", "iso2c")
FH <- FH[, -c(1,2, 3)]
FH<- FH[c(3, 4, 2, 1)]
FH_Clean <- FH %>%
drop_na() %>%
clean_names() %>%
filter(country_name %in% c("Ecuador", "Kazakhstan", "Kyrgyzstan", "Tajikistan", "Turkmenistan", "Uzbekistan"))
```
```{r Map of Central Asia}
Central_Asia <- c("Kazakhstan", "Kyrgyzstan", "Tajikistan", "Turkmenistan", "Uzbekistan")
Central_Asia <- map_data("world", region = Central_Asia)
map.data <- Central_Asia %>%
group_by(region) %>%
summarise(long = mean(long), lat = mean(lat))
colnames(Central_Asia)[colnames(Central_Asia) == 'region'] <- 'country_name'
Central_Asia$country_name <- countrycode(Central_Asia$country_name, "country.name", "country.name")
```
```{r GDP CA Map}
GDP_2018 <- GDP %>%
filter(year == 2018)
GDP_Map <- left_join(Central_Asia, GDP_2018, by = c("country_name"))
GDP_Map2 <- GDP_Map %>%
mutate(GDP = (gdp - mean(gdp))/sd(gdp))
```
```{r GDP CA Comparative Map}
GDP_Map <- ggplot(GDP_Map2, aes( x = long, y = lat, group = group )) +
geom_polygon(aes(fill = GDP), color = "white") +
guides(fill = guide_legend(reverse = T,)) +
scale_fill_continuous(type = "gradient", labels = c("Low GDP", "High GDP"), breaks = c(-1,1)) +
labs(fill = "GDP in USD",
title = 'GDP in Central Asia: 2018',
x = NULL,
y = NULL,
caption = "Source: World Bank") +
theme(text = element_text(color = '#333333'),
plot.title = element_text(size = 12),
plot.subtitle = element_text(size = 10),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.grid = element_blank(),
plot.background = element_rect(fill = '#CCCCCC'),
legend.position = c(.91,.2),
legend.background = element_rect(fill = '#CCCCCC'),
legend.key = element_blank()
)
```
```{r Regime CA Map}
FH_2020<- FH_Clean %>%
filter(year == 2020)
Regime_Map <- left_join(Central_Asia, FH_2020, by = c("country_name"))
```
```{r}
FH_Map <- ggplot(Regime_Map, aes( x = long, y = lat, group = group )) +
geom_polygon(aes(fill = total), color = "white") +
guides(fill = guide_legend(reverse = TRUE)) +
scale_fill_continuous(limits = c(0, 39), labels = c("Not Free", "Partially Free"), breaks = c(0, 39)) +
labs(fill = "Index",
title = 'Freedom House Scores in Central Asia: 2020',
x = NULL,
y = NULL,
caption = "Source: Freedom House") +
theme(text = element_text(color = '#333333'),
plot.title = element_text(size = 12),
plot.subtitle = element_text(size = 10),
axis.ticks = element_blank(),
axis.text = element_blank(),
panel.grid = element_blank(),
plot.background = element_rect(fill = '#CCCCCC'),
legend.position = c(.9,.24),
legend.background = element_rect(fill = '#CCCCCC'),
legend.key = element_blank()
)
```
```{r GDP for All}
GDP_All <- GDP %>%
filter(country_name %in% c("Ecuador", "Kazakhstan", "Kyrgyzstan", "Tajikistan", "Turkmenistan", "Uzbekistan"))
GDP_Line_Graph <- ggplot(GDP_All, aes(x = year, y = gdp, group = country_name)) +
geom_line(aes(linetype= "dash", color = country_name)) +
geom_point(aes(color = country_name)) +
theme_economist_white() +
labs(
color = "Country",
title = "GDP for Central Asia and Ecuador",
x = "Year",
y = "GDP in USD",
caption = "Source: World Bank"
) +
scale_x_discrete(breaks = c(1996, 1998, 2000, 2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020)) +
guides(linetype = FALSE) +
theme(axis.title.y = element_text(vjust = 4), axis.title.x = element_text(vjust = -4), plot.title = element_text(hjust = .45, vjust = 3))
```
```{r Freedom House for All}
FH_All <- FH_Clean %>%
filter(country_name %in% c("Ecuador", "Kazakhstan", "Kyrgyzstan", "Tajikistan", "Turkmenistan", "Uzbekistan"))
FH_Line_Graph <- ggplot(FH_All, aes(x = year, y = total, group = country_name)) +
geom_line(aes(linetype= "dash", color = country_name)) +
geom_point(aes(color = country_name)) +
theme_economist_white() +
labs(
color = "Country",
title = "Freedom House Scores for Central Asia and Ecuador",
x = "Year",
y = "Freedom Index",
caption = "Source: Freedom House"
) +
expand_limits(y = c(0, 100)) +
scale_x_continuous(breaks = c(2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020)) +
guides(linetype = FALSE)+
theme(axis.title.y = element_text(vjust = 4), axis.title.x = element_text(vjust = -4), plot.title = element_text(hjust = .45, vjust = 3))
```