-
Notifications
You must be signed in to change notification settings - Fork 0
/
unfpa.Rmd
253 lines (209 loc) · 8.81 KB
/
unfpa.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
---
title: "International Migrant Stocks 1990-2019"
output: "github_document"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r unfpa, include=FALSE}
library(tidyverse)
getwd()
load("rda/unfpa.rda")
dim(data)
str(data)
summary(data)
```
### Overall
```{r 1, echo=FALSE}
data %>%
mutate(Stock=Stock/1000000) %>%
filter(Area=="Africa" | Area=="Asia"| Area=="Europe"| Area=="Latin America and the Caribbean"| Area=="Northern America"| Area=="Oceania") %>%
mutate(Area=recode(Area,'Latin America and the Caribbean'="Latin America")) %>%
mutate(Area=reorder(Area, -Stock)) %>%
ggplot(aes(x=Year, y=Stock, color=Area))+
geom_point()+
geom_line()+
scale_y_continuous(breaks = seq(0, 100, by = 10))+
scale_x_continuous(breaks = seq(0, 2020, by = 5))+
theme_bw()+
ylab("Migrant Stock (millions)")+
theme(axis.title.x = element_text(vjust=-1))+
theme(axis.title.y = element_text(vjust=2.5))+
theme(legend.title = element_blank())
```
### Overall (cumulative)
```{r 2, echo=FALSE}
data %>%
mutate(Stock=Stock/1000000) %>%
filter(Area=="Africa" | Area=="Asia"| Area=="Europe"| Area=="Latin America and the Caribbean"| Area=="Northern America"| Area=="Oceania") %>%
mutate(Area=recode(Area,'Latin America and the Caribbean'="Latin America")) %>%
mutate(Area=reorder(Area, -Stock)) %>%
ggplot(aes(x=Year, y=Stock, fill=Area))+
geom_area() +
scale_y_continuous(breaks = seq(0, 300, by = 20))+
scale_x_continuous(breaks = seq(0, 2020, by = 5))+
theme_bw()+
ylab("Migrant Stock (millions)")+
theme(axis.title.x = element_text(vjust=-1))+
theme(axis.title.y = element_text(vjust=2.5))+
theme(legend.title = element_blank())
```
### Select European Countries
```{r 3, echo=FALSE}
data %>%
mutate(Stock=Stock/1000000) %>%
filter(Area=="Finland" | Area=="Iceland"| Area=="Ireland"| Area=="Norway"| Area=="Sweden"| Area=="United Kingdom"| Area=="Greece"| Area=="Italy"| Area=="Portugal"| Area=="Spain"| Area=="Austria"| Area=="Belgium"| Area=="France"| Area=="Germany"| Area=="Netherlands"| Area=="Switzerland") %>%
mutate(Area=reorder(Area, -Stock)) %>%
ggplot(aes(x=Year, y=Stock, color=Area))+
geom_point()+
geom_line()+
scale_y_continuous(breaks = seq(0, 20, by = 1))+
scale_x_continuous(breaks = seq(0, 2020, by = 5))+
theme_bw()+
ylab("Migrant Stock (millions)")+
theme(axis.title.x = element_text(vjust=-1))+
theme(axis.title.y = element_text(vjust=2.5))+
theme(legend.title = element_blank())
```
### Select European Countries (cumulative)
```{r 4, echo=FALSE}
data %>%
mutate(Stock=Stock/1000000) %>%
filter(Area=="Finland" | Area=="Iceland"| Area=="Ireland"| Area=="Norway"| Area=="Sweden"| Area=="United Kingdom"| Area=="Greece"| Area=="Italy"| Area=="Portugal"| Area=="Spain"| Area=="Austria"| Area=="Belgium"| Area=="France"| Area=="Germany"| Area=="Netherlands"| Area=="Switzerland") %>%
mutate(Area=reorder(Area, -Stock)) %>%
ggplot(aes(x=Year, y=Stock, fill=Area))+
geom_area()+
scale_y_continuous(breaks = seq(0, 80, by = 5))+
scale_x_continuous(breaks = seq(0, 2020, by = 5))+
theme_bw()+
ylab("Migrant Stock (millions)")+
theme(axis.title.x = element_text(vjust=-1))+
theme(axis.title.y = element_text(vjust=2.5))+
theme(legend.title = element_blank())
```
### Africa (top 10)
```{r 5, echo=FALSE}
africa <- data %>%
slice(c(134:269, 277:339, 347:381, 389:507, 522:570)) %>%
mutate(Area = recode(Area, 'Democratic Republic of the Congo'='Congo', 'United Republic of Tanzania'='Tanzania'))
africa %>%
mutate(Stock=Stock/1000000) %>%
filter(Stock > 0.9) %>%
mutate(Area=reorder(Area, Stock)) %>%
ggplot(aes(as.factor(Year), Area, fill=Stock))+
geom_tile()+
scale_fill_gradientn(colors = RColorBrewer::brewer.pal(3, "Greens"))+
theme_bw()+
theme(panel.grid = element_blank())+
ylab("Country")+xlab("Year")+
theme(axis.title.x = element_text(vjust=-1))+
labs(fill = "Stock (millions)")
```
### Asia (top 10)
```{r 8, echo=FALSE}
asia <- data %>%
slice(c(718:752, 760:822, 837:885, 893:969))%>%
mutate(Area = recode(Area, 'Iran (Islamic Republic of)'='Iran', 'China, Hong Kong SAR'='Hong Kong'))
asia %>%
mutate(Stock=Stock/1000000) %>%
filter(Stock > 1.8) %>%
mutate(Area=reorder(Area, Stock)) %>%
ggplot(aes(as.factor(Year), Area, fill=Stock))+
geom_tile()+
scale_fill_gradientn(colors = RColorBrewer::brewer.pal(3, "Greens"))+
theme_bw()+
theme(panel.grid = element_blank())+
ylab("Country")+xlab("Year")+
theme(axis.title.x = element_text(vjust=-1))+
labs(fill = "Stock (millions)")
```
### Europe (top 10)
```{r 6, echo=FALSE}
europe <- data %>%
slice(c(1543:1612, 1620:1710, 1718:1825, 1833:1895)) %>%
mutate(Area = recode(Area, 'United Kingdom'='UK'))
europe %>%
filter(Area!="Russian Federation") %>%
mutate(Stock=Stock/1000000) %>%
filter(Stock > 1.9) %>%
mutate(Area=reorder(Area, Stock)) %>%
ggplot(aes(as.factor(Year), Area, fill=Stock))+
geom_tile()+
scale_fill_gradientn(colors = RColorBrewer::brewer.pal(3, "Greens"))+
theme_bw()+
theme(panel.grid = element_blank())+
ylab("Country")+xlab("Year")+
theme(axis.title.x = element_text(vjust=-1))+
labs(fill = "Stock (millions)")
```
### World (2019, top 20)
```{r 7, echo=FALSE}
world <- data %>%
filter(Year=="2019") %>%
slice(c(-1:-19, -40, -50, -56, -74, -75, -83, -102, -103, -109, -119, -120, -128, -140, -141, -168, -177, -192, -193, -196, -202, -210, -220:-222, -233, -247, -264, -274)) %>%
mutate(Area = recode(Area, 'Democratic Republic of the Congo'='Congo', 'United Republic of Tanzania'='Tanzania', 'United States of America'='USA', 'China, Hong Kong SAR' = 'Hong Kong', 'Iran (Islamic Republic of)'='Iran', 'Venezuela (Bolivarian Republic of)'='Venezuela', 'Republic of Korea'='South Korea', 'United Arab Emirates'='Emirates', 'Russian Federation'='Russia', 'United Kingdom' = 'UK'))
world %>%
mutate(Stock=Stock/1000000) %>%
filter(Stock>3.2) %>%
mutate(Area=reorder(Area, -Stock)) %>%
ggplot(aes(x=Area, y=Stock, fill = Area))+
geom_col()+
theme_bw()+
theme(legend.position = "none")+
scale_y_continuous(breaks = seq(0, 60, by = 3))+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
ylab("Stock (millions)")+xlab("Country")+
theme(axis.title.y = element_text(vjust=2))
```
## In percent of population (Select European Countries)
```{r 9, echo=FALSE}
load("rda/unfpa_percent.rda")
data %>%
filter(Area=="Finland" | Area=="Iceland"| Area=="Ireland"| Area=="Norway"| Area=="Sweden"| Area=="United Kingdom"| Area=="Greece"| Area=="Italy"| Area=="Portugal"| Area=="Spain"| Area=="Austria"| Area=="Belgium"| Area=="France"| Area=="Germany"| Area=="Netherlands"| Area=="Switzerland") %>%
mutate(Area=reorder(Area, -Percent)) %>%
ggplot(aes(x=Year, y=Percent, color=Area))+
geom_point()+
geom_line()+
scale_y_continuous(breaks = seq(0, 40, by = 5))+
scale_x_continuous(breaks = seq(0, 2020, by = 5))+
theme_bw()+
ylab("Percent of Population")+
theme(axis.title.x = element_text(vjust=-1))+
theme(axis.title.y = element_text(vjust=2.5))+
theme(legend.title = element_blank())
```
## In percent of population (2019, top 50)
```{r 10, echo=FALSE, fig.height=8, fig.width=7}
world <- data %>%
filter(Year=="2019") %>%
slice(c(-1:-19, -40, -50, -56, -74, -75, -83, -102, -103, -109, -119, -120, -128, -140, -141, -168, -177, -192, -193, -196, -202, -210, -220:-222, -233, -247, -264, -274)) %>%
mutate(Area = recode(Area, 'Democratic Republic of the Congo'='Congo', 'United Republic of Tanzania'='Tanzania', 'United States of America'='USA', 'China, Hong Kong SAR' = 'Hong Kong', 'Iran (Islamic Republic of)'='Iran', 'Venezuela (Bolivarian Republic of)'='Venezuela', 'Republic of Korea'='South Korea', 'United Arab Emirates'='Emirates', 'Russian Federation'='Russia', 'United Kingdom' = 'UK'))
world %>%
filter(Percent>19.9) %>%
mutate(Area=reorder(Area, Percent)) %>%
ggplot(aes(x=Area, y=Percent, fill = Area))+
geom_col()+
theme_bw()+
theme(legend.position = "none")+
scale_y_continuous(breaks = seq(0, 100, by = 5))+
ylab("Percent of population")+xlab("Country")+
theme(axis.title.y = element_text(vjust=2))+
theme(axis.title.x = element_text(vjust=-1))+
coord_flip()
```
## In percent of population (2019, bottom 50)
```{r 11, echo=FALSE, fig.height=8, fig.width=7}
world %>%
filter(Percent<1.4) %>%
mutate(Area=reorder(Area, Percent)) %>%
ggplot(aes(x=Area, y=Percent, fill = Area))+
geom_col()+
theme_bw()+
theme(legend.position = "none")+
scale_y_continuous(breaks = seq(0, 2, by = 0.1))+
ylab("Percent of population")+xlab("Country")+
theme(axis.title.y = element_text(vjust=2))+
theme(axis.title.x = element_text(vjust=-1))+
coord_flip()
```
Source: United Nations, Department of Economic and Social Affairs. Population Division (2019). International Migrant Stock 2019 (United Nations database, POP/DB/MIG/Stock/Rev.2019)