This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
/
index.Rmd
195 lines (162 loc) · 8.26 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
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
---
title: "Exploring the Geo-PKO dataset"
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 extract meaningful information the Geo-PKO dataset. More details on the dataset, as well as the version used here, can be found on its [homepage](https://www.pcr.uu.se/data/geo-pko/).
## Setting up
Load packages.
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
library(readr)
library(ggthemes)
library(knitr)
library(kableExtra)
```
Import the dataset.
```{r, warning=FALSE, message =FALSE}
GeoPKO <- read_csv("data/geopko.csv")
```
## An overview
Let's have a quick look at the first few rows of the dataset.
```{r}
kable(GeoPKO[1:5,]) %>% kable_styling() %>%
scroll_box(width = "100%", height = "200px")
```
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
```
### What missions are included?
The following table provides users with a list of missions and the duration for which they are covered by the dataset.
```{r}
GeoPKO$Start <- ave(GeoPKO$year, GeoPKO$Mission, FUN = min)
GeoPKO$End <- ave(GeoPKO$year, GeoPKO$Mission, FUN = max)
Years <- GeoPKO %>% select(Mission, Start, End)
Years <- Years %>% group_by(Start, End, Mission) %>% distinct()
kable(Years[,], caption = "UN Missions in the GeoPKO dataset") %>% kable_styling()
```
### Number of troops
## Visualizing deployment locations
An advantage to the Geo-PKO dataset is that it records the numbers of troops by their specific deployment locations. Therefore, users can quickly visualize *where* active troops are in a mission. Below are some examples of visuaization.
First, we can produce 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, year, location, latitude, longitude, No.troops, HQ, country)
map2018df1 <- map2018df %>% group_by(location, Mission) %>%
mutate(ave = mean(No.troops, na.rm=TRUE)) %>% distinct()
kable(map2018df1[90:95,], caption = "A preview of this dataframe") %>% kable_styling()
```
Next, we obtain the geometric shapes from `rnaturalearth`, and filter for countries in Africa.
```{r, warning=FALSE, message=FALSE}
library(rnaturalearth)
library(rnaturalearthdata)
library(sf)
world <- ne_countries(scale = "medium", returnclass = "sf")
Africa <- world %>% filter(region_un == "Africa")
```
```{r, warning=FALSE, message=FALSE}
library(ggrepel)
library(viridis)
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", range=c(1,12), breaks=c(0, 100, 300, 500, 1000, 2000, 3000, 4000,5000)) +
scale_color_viridis(option="cividis", breaks=c(0, 100, 300, 500, 1000, 2000, 3000, 4000,5000), name="Average Troop Deployment" ) +
guides( colour = guide_legend()) +
geom_point(data = map2018df1 %>% filter(HQ==3), aes (x=longitude, y=latitude), color = "red", shape = 4, size=7)+
geom_label_repel(data = map2018df1 %>% filter(HQ==3), aes(x=longitude, y=latitude, label=Mission)) +
labs (title ="UN Peacekeeping Deployment in Africa - 2018 (approx.)", color='Average Troop Deployment') +
theme(
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")),
panel.grid=element_blank(),
axis.title=element_blank(),
axis.ticks=element_blank(),
axis.text=element_blank(),
legend.key=element_blank()
)
p2
```
Here is the same map, but this time the points show both troop size and country.
```{r, warning=FALSE, message=FALSE, out.width="100%"}
p3 <- ggplot(data=Africa) + geom_sf() +
geom_point(data=map2018df1,
aes(x=longitude, y=latitude, size=ave, color=country), alpha=.4)+
geom_point(data=map2018df1 %>%
filter(HQ==3),
aes(x=longitude, y=latitude), color="black", shape=16, size=2
) +
geom_label_repel(
data=map2018df1 %>%
filter(HQ==3),
min.segment.length = 0.2,
label.size = 0.5,
box.padding = 2,
size = 3,
aes(x=longitude, y=latitude, label=Mission)
) +
labs(title="UN Peacekeeping Deployment and Mission HQs in Africa, 2018")+
scale_size(range = c(2, 16))+
labs(size="Average number of troops (continuous scale)",col="Country",shape="HQ")+
theme(
plot.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")),
panel.grid=element_blank(),
axis.title=element_blank(),
axis.ticks=element_blank(),
axis.text=element_blank(),
panel.background=element_blank()
)
p3
```
How has this changed over the period covered by the dataset? An animated graph is great for this purpose. The first step is to prepare a dataframe, much similar to what has been done above for 2018. First we would calculate the average number of troops that is deployed to a location per mission per year.
```{r}
gif_df <- GeoPKO %>% select(Mission, year, location, latitude, longitude, No.troops, HQ) %>%
group_by(Mission, year, location) %>%
mutate(ave.no.troops = as.integer(mean(No.troops, na.rm=TRUE))) %>% select(-No.troops) %>% distinct() %>% drop_na(ave.no.troops)
```
Next, we add animation to the above map using the package `gganimate`.
```{r, animatedgraph, warning=FALSE, dev="png", interval=0.5}
library(gganimate)
# Transforming the "year" variable into a discrete variable.
gif_df$year <- as.factor(gif_df$year)
ggplot(data=Africa) + geom_sf() +
geom_point(data = gif_df, aes(x=longitude, y=latitude, size= ave.no.troops, color= ave.no.troops, group=year), alpha=.7)+
scale_size_continuous(name="Average Troop Deployment", range=c(1,12), breaks=c(0, 100, 300, 500, 1000, 2000, 3000, 4000,5000)) +
scale_color_viridis(option="cividis", breaks=c(0, 100, 300, 500, 1000, 2000, 3000, 4000,5000), name="Average Troop Deployment" ) +
guides(colour = guide_legend()) +
theme(
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")),
panel.grid=element_blank(),
axis.text=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
legend.key=element_blank(),
plot.caption=element_text(hjust=0, face="italic"))+
transition_states(states=year, transition_length = 3, state_length=3)+
labs(title="UN Peacekeeping in intrastate armed conflicts in Africa: {closest_state}",
color="Average Deployment Size",
caption="Source: The GeoPKO dataset 1.2")+
enter_fade()
#run the following command to save the plot
#anim_save("animatedUNPKO.gif", p4)
```