This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
/
index.Rmd
94 lines (76 loc) · 3.77 KB
/
index.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
---
title: "Analysis"
site: workflowr::wflow_site
output:
workflowr::wflow_html:
toc: false
editor_options:
chunk_output_type: console
---
This document contains a series of steps that the project members have performed to explore the Geo-PKO dataset. More information on the dataset can be found on its [homepage](https://www.pcr.uu.se/data/geo-pko/).
Load packages.
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
library(readr)
library(ggthemes)
library(knitr)
```
Import the dataset.
```{r, warning=FALSE, message =FALSE}
GeoPKO <- read_csv("data/geopko.csv")
```
Now we can start with the actual fun stuff! Let's have a quick look at the first few rows of the dataset.
```{r}
head(GeoPKO)
```
The dataset covers UN peacekeeping missions in Africa between 1994 and 2018. We can use the dataset to extract the number of active missions during this period.
```{r}
NoMission <- GeoPKO %>% select(year, Mission) %>% distinct(year, Mission) %>% count(year)
Plot1 <- ggplot(NoMission, aes(x=(as.numeric(year)), y=n)) + geom_point() + geom_line(size=0.5) +
scale_x_continuous("Year", breaks=seq(1994, 2018, 1))+theme_classic()+
scale_y_continuous("Number of missions", breaks=seq(0,10,1)) +
theme(panel.grid=element_blank(),
axis.text.x=element_text(angle=45, vjust=0.5))
Plot1
```
We want to have a quick snapshot of the deployment size in 2018, as well as the missions that were active in that year. We start by subsetting the main dataset to include entries for the year of 2018 and our variables of interests. GeoPKO reports deployment sizes according to the available maps published by the UN. Therefore, to obtain the numbers of troop deployment at the yearly level, we calculate the average number of troops per location over the months recorded.
```{r}
GeoPKO$No.troops <- as.numeric(GeoPKO$No.troops)
map2018df <- GeoPKO %>% filter(year==2018) %>%
select(Mission, month, location, latitude, longitude, No.troops, HQ)
map2018df1 <- map2018df %>% group_by(location, latitude, longitude, Mission, HQ) %>%
summarize(ave = mean(No.troops, na.rm=TRUE)) %>% ungroup()
kable(map2018df1[1:5,], caption = "A preview of this dataframe")
```
Next, we obtain the geometric shapes from `rnaturalearth`, and filter for countries in Africa.
```{r}
library(rnaturalearth)
library(rnaturalearthdata)
library(sf)
world <- ne_countries(scale = "medium", returnclass = "sf")
Africa <- world %>% filter(region_un == "Africa")
```
Finally, we plot our data onto the map.
```{r}
library(ggrepel)
mybreaks <- c(0, 100, 300, 500, 1000, 2000, 3000, 4000,5000)
p2 <- ggplot(data=Africa) + geom_sf() +
geom_point(data = map2018df1, aes(x=longitude, y=latitude, size= ave, color= ave), alpha=.7)+
scale_size_continuous(name="Average Troop Deployment", trans="log", range=c(1,12), breaks=mybreaks) +
scale_alpha_continuous(name="Average Troop Deployment", trans="log", range=c(0.1, .9), breaks=mybreaks)+
scale_color_viridis(option="cividis", trans="log", breaks=mybreaks, name="Average Troop Deployment" ) +
guides( colour = guide_legend()) +
geom_point(data = map2018df1 %>% filter(HQ==3), aes (x=longitude, y=latitude), color = "red", shape = 3, size=10)+
geom_label_repel(data = map2018df1 %>% filter(HQ==3), aes(x=longitude, y=latitude, label=Mission)) +
labs (title ="UN Peacekeeping Deployment in Africa - 2018 (approx.)") +
labs(color='Average Troop Deployment') +
theme(
legend.position = c(0.2, 0.3),
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#f5f5f2", color = NA),
panel.background = element_rect(fill = "#f5f5f2", color = NA),
legend.background = element_rect(fill = "#f5f5f2", color = NA),
plot.title = element_text(size= 14, hjust=0.01, color = "#4e4d47", margin = margin(b = -0.1, t = 0.8, l = 4, unit = "cm")),
)
p2
```