forked from Edouard-Legoupil/unhcrdatapackage
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Refugee_Status_Determination_Application.Rmd
138 lines (113 loc) · 5.5 KB
/
Refugee_Status_Determination_Application.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
---
title: "Refugee Status Determination Application"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Refugee Status Determination Application}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
echo=TRUE,
comment = "#>"
)
```
## Load Packages
```{r message=FALSE, warning=FALSE}
library(tidyverse)
```
## Prepare Data
```{r}
thisbureau <- "Americas"
lastyear <- max(unhcrdatapackage::end_year_population_totals_long$Year)
topasyl <- unhcrdatapackage::asylum_decisions %>%
## Add reference for the filters
dplyr::left_join( unhcrdatapackage::reference %>%
select(coa_region = `UNHCRBureau`, iso_3), by = c("CountryAsylumCode" = "iso_3")) %>%
filter(coa_region == thisbureau & Year == lastyear) %>%
# select(region_asy, ctry_asy, year, recognizedConvMandate, recognizedOther, appliedDuringTheYear, meta_applicationAveragePersonsPerCase) %>%
mutate(DecisionsAveragePersonsPerCase = map_dbl(DecisionsAveragePersonsPerCase, ~replace_na(max(as.numeric(.), 1), 1))) %>%
group_by(CountryAsylumName) %>%
summarize(Recognized = sum(Recognized * DecisionsAveragePersonsPerCase, na.rm = TRUE),
ComplementaryProtection = sum(ComplementaryProtection * DecisionsAveragePersonsPerCase, na.rm = TRUE),
TotalDecided = sum(TotalDecided * DecisionsAveragePersonsPerCase, na.rm = TRUE)) %>%
mutate(RefugeeRecognitionRate = (Recognized ) / TotalDecided,
GlobalRecognitionRate = (Recognized + ComplementaryProtection) / TotalDecided ) %>%
filter(TotalDecided != 0) %>%
filter(TotalDecided > 1000) %>%
mutate(CountryAsylumName = str_replace(CountryAsylumName, "United States of America", "USA"))
topasyl1 <- topasyl %>%
arrange(desc(TotalDecided)) %>%
head(10)
topOrigin <- unhcrdatapackage::asylum_decisions %>%
## Add reference for the filters
dplyr::left_join( unhcrdatapackage::reference %>%
select(coa_region = `UNHCRBureau`, iso_3), by = c("CountryOriginCode" = "iso_3")) %>%
filter(coa_region == thisbureau & Year == lastyear) %>%
# select(region_asy, ctry_asy, year, recognizedConvMandate, recognizedOther, appliedDuringTheYear, meta_applicationAveragePersonsPerCase) %>%
mutate(DecisionsAveragePersonsPerCase = map_dbl(DecisionsAveragePersonsPerCase, ~replace_na(max(as.numeric(.), 1), 1))) %>%
group_by(CountryOriginName) %>%
summarize(Recognized = sum(Recognized * DecisionsAveragePersonsPerCase, na.rm = TRUE),
ComplementaryProtection = sum(ComplementaryProtection * DecisionsAveragePersonsPerCase, na.rm = TRUE),
TotalDecided = sum(TotalDecided * DecisionsAveragePersonsPerCase, na.rm = TRUE)) %>%
mutate(RefugeeRecognitionRate = (Recognized ) / TotalDecided,
GlobalRecognitionRate = (Recognized + ComplementaryProtection) / TotalDecided) %>%
filter(TotalDecided != 0) %>%
filter(TotalDecided > 1000) %>%
mutate(CountryOriginName = str_replace(CountryOriginName, " \\(Bolivarian Republic of\\)", ""))
topOrigin1 <- topOrigin %>%
arrange(desc(TotalDecided)) %>%
head(10)
```
# Generate plot
```{r ,fig.height=7, fig.width=7, warning=FALSE, echo = TRUE ,message=FALSE}
rsdasyl <- ggplot(topasyl1, aes(y = TotalDecided,
x = reorder(CountryAsylumName, TotalDecided))) +
scale_y_continuous( label = scales::label_number_si()) + ## Format axis number
#facet_grid(.~ ctry_asy) +
geom_bar( stat ="identity", fill = unhcRstyle::unhcr_blue) +
coord_flip() +
labs(#title = "Number of RSD application in 2020",
subtitle = "Per country of asylum",
x = " ",
y = " " ) +
unhcRstyle::unhcr_theme(base_size = 9) +
theme(#axis.text.x = element_blank(),
# legend.position = "none",
panel.grid.major.x = element_line(color = "#cbcbcb"),
panel.grid.major.y = element_blank()) +### changing grid line that should appear) +
geom_hline(yintercept = 0, size = 1.1, colour = "#333333")
##############################################################
##############################################################
rsdorigin <- ggplot(topOrigin1, aes(y = TotalDecided,
x = reorder(CountryOriginName, TotalDecided))) +
scale_y_continuous( label = scales::label_number_si()) + ## Format axis number
#facet_grid(.~ ctry_asy) +
geom_bar( stat ="identity", fill = unhcRstyle::unhcr_blue) +
coord_flip() +
labs(#title = "Number of RSD application per country of Origin in 2020",
subtitle = "Per country of Origin",
x = " ",
y = " " ) +
unhcRstyle::unhcr_theme(base_size = 9) +
theme(#axis.text.x = element_blank(),
# legend.position = "none",
panel.grid.major.x = element_line(color = "#cbcbcb"),
panel.grid.major.y = element_blank()) +### changing grid line that should appear) +
geom_hline(yintercept = 0, size = 1.1, colour = "#333333")
##########################
#joining charts
##################
library(patchwork)
patchworkRSDa <- rsdasyl + rsdorigin
patchworkRSDa1 <- patchworkRSDa +
#unhcRstyle::unhcr_theme(base_size = 8) + ## Insert UNHCR Style
theme(legend.position = "none") +
plot_annotation(
title = 'Number of RSD applications in 2020 in the Americas ',
# subtitle = ' ',
caption = 'Source: UNHCR.org/refugee-statistics - Only Countries of Origin with more than 1,000 application during 2020 -\n Because of different types of procedure, data from the US may \n includes multiple applications per applicants compared to other countries '
)
patchworkRSDa1
```