This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
/
merge.Rmd
524 lines (444 loc) · 24.7 KB
/
merge.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
---
title: "Integrating Conflict Data"
output:
workflowr::wflow_html:
toc: false
editor_options:
chunk_output_type: console
---
This page shows how to merge Geo-PKO data with conflict data and visualise the results. The examples used here are Uppsala University's Violence Early Warning System (ViEWS) project, which forecasts conflict risk, and the Uppsala Conflict Data Programme (UCDP), one of the world's leading sources of data on armed conflict. Merging these datasets can provide insights into the links between conflict risk and peacekeeping deployments, and help policymakers make effective peacekeeping decisions where the risk of conflict is high.
## Setting up
Load packages.
```{r, warning=FALSE, message=FALSE}
library(dplyr)
library(sp)
library(tidyr)
library(geojsonio)
library(broom)
library(rgdal)
library(ggplot2)
library(leaflet)
library(sf)
library(spdep)
library(maptools)
library(plyr)
library(rjson)
library(RJSONIO)
library(rmapshaper)
library(htmltools)
library(htmlwidgets)
library(leaflet.providers)
library(kableExtra)
```
## Geo-PKO x ViEWS
This visualisation aims to show peacekeeping deployments and projected conflict risk for the following 36 months. It helps us visualise conflict forecasts for locations where peacekeepers are deployed and better understand the relationship between peacekeeping deployments and conflict risk (for example, the risk levels at which peacekeeping deployments are more likely).
First, we import the datasets. We're using the published Geo-PKO dataset, and conflict forecast data from ViEWS for state-based conflict, non-state conflict, and one-sided violence over the next 36 months in Africa. Both datasets offer insights into the sub-national level, using a unique "PRIO-grid" identifier. The PRIO-grid is an innovative geospatial unit from the Peace Research Institute Oslo that divides the world into roughly 100km x 100km squares, allowing geographic analysis beyond the country level to be streamlined.
```{r, warning=FALSE, message=FALSE}
library(readr)
geopko <- readr::read_csv("C:/Users/tanus/Dropbox/Geo-PKO working material for v 2.0/Dataset v.2.0/Geo_PKO_v.2.0.csv")
#unzip("data/ViEWS.zip", exdir="data/ViEWS")
predictors <- read.csv("C:/Users/tanus/Documents/R/GeoPKO/data/ViEWS/ensemble_pgm.csv")
```
The Geo-PKO dataset includes detail on troop deployment numbers, types of troops, non-troop deployments, and contributing countries.
```{r, warning=FALSE, message=FALSE}
kable(geopko[9546:9550,]) %>% kable_styling() %>%
scroll_box(width = "100%", height = "200px")
```
### Preparing the data
The predictor database begins with July 2020 and forecasts the risk of conflict over the next 36 months ahead. Here's a preview of the data within it, showing state-based (`sb`), non-state (`ns`) and one-sided violence (`os`) forecasts. The variable `month_id` codes months differently to the Geo-PKO dataset, with every month assigned a different numeric value.
```{r, warning=FALSE, message=FALSE}
kable(predictors[90545:90550,]) %>% kable_styling() %>%
scroll_box(width = "100%", height = "200px")
```
You'll see both the Geo-PKO and ViEWS datasets include the PRIO-grid identification variable (`pg_id or prioid`), which corresponds to a specific grid square on the map. This is what we'll use to eventually merge the datasets.
We first need to filter the Geo-PKO data to include only deployments over the relevant time period. We are choosing to visualise deployments between July 2019 - June 2020 and conflict risk for the following 36 months (2020-2023). We also remove countries outside Africa, as the ViEWS dataset only covers this continent.
_Note: 2020 data is not currently available, but will be in early 2021. The dataset used for this visualisation will then be updated._
```{r, warning=FALSE, message=FALSE}
# filtering for troop deployments over July 2019 - June 2020 in Africa
geopko2 <- geopko %>%
select(mission, month, year, prioid, no.troops, country, location, latitude, longitude) %>%
dplyr::mutate_at(vars(longitude, latitude, month, year, no.troops), as.numeric) %>%
filter(year==2019 & month>6 | year==2020 & month <7) %>%
filter(country != "Kosovo" & country != "Lebanon" & country != "Haiti" & country != "Syria" & country != "Cyprus")
```
We now need to calculate the average number of troops deployed over that time period. In the visualisation, we'll use coordinates to map deployment locations, so the average is calculated by location. The following script also shows how to end up with an average number of deployed troops for each PRIO-grid square, which we won't visualise in this example, but is useful to understand how to merge the data.
```{r, warning=FALSE, message=FALSE}
# calculating an average number of troops per location
geopko3 <- geopko2 %>%
group_by(location) %>%
filter (! duplicated(no.troops)) %>%
dplyr::mutate(no.troops = mean(no.troops, na.rm=TRUE)) %>%
dplyr::mutate(no.troops=round(no.troops)) %>%
filter (! duplicated(no.troops)) %>%
ungroup() %>%
select(-month)
# summing troop count by priogrid id
geopko4 <- geopko3 %>%
group_by(prioid) %>%
dplyr::mutate(no.troops = sum(no.troops, na.rm=TRUE)) %>%
filter (! duplicated(no.troops)) %>%
ungroup() %>%
select(-location)
```
Next, we can calculate the average conflict risk (state-based, non-state, and one-sided) for each PRIO-grid square over the time period we're provided with.
```{r, warning=FALSE, message=FALSE}
predictors2 <- predictors %>%
group_by(pg_id) %>%
dplyr::mutate(average_allwthematic_sb = mean(average_allwthematic_sb, na.rm=TRUE)) %>%
dplyr::mutate(average_allwthematic_ns = mean(average_allwthematic_ns, na.rm=TRUE)) %>%
dplyr::mutate(average_allwthematic_os = mean(average_allwthematic_os, na.rm=TRUE)) %>%
filter (! duplicated(pg_id)) %>%
ungroup() %>%
select(-month_id)
```
Finally, we merge the two datasets.
```{r, warning=FALSE, message=FALSE}
# merging geopko with conflict forecast data (averaged)
geopko4$pg_id <- geopko4$prioid
priogriddf <- full_join(
geopko4, predictors2,
by = c("pg_id"),
na.rm = TRUE)
```
### Merging the dataframe with the shapefile
Like we mentioned before, the PRIO-grid unit involves dividing the entire world into roughly 100km x 100km squares. That means that if we want to map it, we'll be working with large files, so keep that in mind when you're reading in the shapefile.
```{r, message=FALSE, warning=FALSE}
shapefile <- rgdal::readOGR("C:/Users/tanus/Documents/R/R Files/ViEWS/priogrid.geojson")
```
The shapefile contains both geospatial polygon data and numerical data that corresponds to the ViEWS dataset; specifically, a PRIO-grid ID and a country ID. To work with the data within this shapefile, we need to fortify it. This converts it into a dataframe. We also convert the IDs to rownames to make it easier to work with. And, finally, we merge it with `pgnewdf2`, which we created earlier.
```{r, warning=FALSE, message=FALSE}
# fortify
shapefile@data$id <- rownames(shapefile@data)
shapefile.df <- fortify(shapefile, region = "id")
# merge data
shapefile.df <- merge(shapefile, priogriddf, by.x = "pg_id", by.y = "pg_id", all.x=F, all.y=T, duplicateGeoms=TRUE)
```
Now `shapefile.df` has the new attributes, including variables from both Geo-PKO and ViEWS. `id` is a variable that ties the 'polygon', or a single square on the grid, to its location on the map. As many PRIO-grid squares will have a conflict forecast index but no troop deployments, many data points under Geo-PKO variables will show NA.
```{r, warning=FALSE, message=FALSE}
kable(shapefile.df@data[5386:5390,]) %>% kable_styling() %>%
scroll_box(width = "100%", height = "200px")
```
### Mapping ViEWS data with Geo-PKO
To map the data, we're going to use the `leaflet` package (and a bunch of others to support it). The first thing we do is set up our colour palette and bins. We're using the 'viridis' colour palette, designed for accessibility and continuous-scale representation. The other thing we include is a small segment of code that fixes spacing between any NA value in the legend, and the remainder of the legend, making it easier to see.
```{r, warning=FALSE, message=FALSE}
bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorNumeric("viridis", NULL)
#to fix spacing of NA in legend
css_fix <- "div.info.legend.leaflet-control br {clear: both;}" # CSS to correct spacing
html_fix <- htmltools::tags$style(type = "text/css", css_fix) # Convert CSS to HTML
```
Next, let's map. We include three colour layers to shade squares according to their conflict forecast value. These layers can be toggled between state-based conflict, non-state conflict, and one-sided violence. Troop deployment numbers are included as labels, which you can see for each square on hover. Labels for specific deployment locations also show the name of the location and country, on hover over location markers.
_Zoom in for more detail._
```{r, warning=FALSE, message=FALSE}
map <- leaflet(shapefile.df) %>%
addTiles() %>%
addPolygons(
color = "#444444", weight = 0.25, smoothFactor = 0.5,
opacity = 0.05, fillOpacity = 0.4,
fillColor = ~ pal(shapefile.df@data$average_allwthematic_sb),
group = "State-Based Conflict",
highlightOptions = highlightOptions(
color = "white", weight = 2,
bringToFront = TRUE
)
) %>%
addPolygons(
color = "#444444", weight = 0.25, smoothFactor = 0.5,
opacity = 0.05, fillOpacity = 0.4,
fillColor = ~ pal(shapefile.df@data$average_allwthematic_ns),
group = "Non-State Conflict",
highlightOptions = highlightOptions(
color = "white", weight = 2,
bringToFront = TRUE
)
) %>%
addPolygons(
color = "#444444", weight = 0.25, smoothFactor = 0.5,
opacity = 0.05, fillOpacity = 0.4,
fillColor = ~ pal(shapefile.df@data$average_allwthematic_os),
group = "One-Sided Violence",
highlightOptions = highlightOptions(
color = "white", weight = 2,
bringToFront = TRUE
)
) %>%
# these circle markers use geopko3 data to cover multiple locations per prioid
addCircleMarkers((data <- geopko3$no.troops),
lat = ~latitude, lng = ~longitude,
weight = 1, radius = 2, fillOpacity = 0.6, color = "darkblue",
group = "Deployment Locations",
label = paste(
"<strong>Deployment Location</strong>", "- ", geopko3$mission,
"<br/><strong>Number of Troops: </strong>", geopko3$no.troops,
"<br/><strong>Location: </strong>", geopko3$location,", ", geopko3$country
)
%>%
lapply(htmltools::HTML)
) %>%
addLegend("bottomright",
pal = pal,
values = shapefile.df$average_allwthematic_sb,
title = "Conflict Forecast",
opacity = 1
) %>%
addLayersControl(
baseGroups = c("State-Based Conflict", "Non-State Conflict", "One-Sided Violence"),
overlayGroups = c("Deployment Locations"),
options = layersControlOptions(collapsed = FALSE)
) %>%
htmlwidgets::prependContent(html_fix) # legend NA fix
map
```
And here we have it: an interactive map to view the latest peacekeeping data and projected conflict risk over the following 36 months. You can zoom in to areas of higher conflict risk to see more detail, including deployment locations. Note that some marked locations still say 0 for troop count; this indicates a mission site where no troops are deployed, but support personnel such as UNPOL or UNMO are present.
We can also do the same but with a world terrain basemap to identify, at a basic level, potential geographic impacts such as the greater concentration of conflict risk in mountainous areas, and the general deployment of peacekeepers in non-mountainous areas.
```{r, warning=FALSE, message=FALSE}
# adding provider tiles - replaces addTiles()
map <- map %>% addProviderTiles("Esri.WorldTerrain")
map
```
Extensions of this visualisation can be even more useful, particularly with a time-slider that can help us identify how the risk of conflict changes given peacekeeping deployments (and vice versa). That would be a valuable be a project for the future.
# Geo-PKO x UCDP
Another useful dataset is from the Uppsala Conflict Data Programme, which offers insights into deaths from armed conflict. Looking at this data in conjunction with peacekeeping data can be useful to draw conclusions into peacekeeping given the severity of armed conflict, or lack thereof. We start by importing the "UCDP Georeferenced Event Dataset (GED) Global version 20.1", of which a small excerpt of 2011 is shown in the table below.
```{r, warning=FALSE, message=FALSE}
UCDP <- read_csv("data/UCDP/ged201.csv")
kable(UCDP[9546:9550,]) %>% kable_styling() %>%
scroll_box(width = "100%", height = "200px")
```
## Preparing the data
For the Geo-PKO data we only use certain variables, and calculate the average troop number by year. The UCDP data has different variables you could use. In this example we took `best`, which indicates "the best (most likely) estimate of total fatalities resulting from integer an event" and `deaths_civilians`, which tells us how many of this `best` variable were civilian deaths.
```{r, warning=FALSE, message=FALSE}
# Preparing the Geo-PKO dataset
GeoPKO_dataUCDP <- geopko %>%
select(mission, year, location, latitude, longitude, no.troops) %>% # Select only the variables you need
mutate_at(vars(latitude, longitude, no.troops), as.numeric) %>%
group_by(mission, year, location) %>%
mutate(ave.no.troops = as.integer(mean(no.troops, na.rm = TRUE))) %>% # Sum the troop numbers by year through using a combination of group_by & mutate
select(-no.troops) %>% # Deselect the previous troop number variable
distinct() %>% # Delete any duplicate rows
drop_na(ave.no.troops) %>% # Remove NAs from the average troop count
filter(ave.no.troops > 0) # Exclude any troop numbers under the value of 0
# Preparing the UCDP dataset
UCDP_dataframe <- UCDP %>%
select(year, longitude, latitude, where_coordinates, best, deaths_civilians) %>%
drop_na(latitude, longitude) %>%
group_by(year, where_coordinates) %>%
mutate(best = as.integer(mean(best, na.rm = TRUE))) %>% # Take the mean of the "best" variable
mutate(deaths_civilians = as.integer(mean(deaths_civilians, na.rm = TRUE))) %>% # Take the mean of the "deaths_civilians" variable
filter(best > 0 & year >= 1995) %>% # Filter that data so that it only keeps rows for the years after 1995.
distinct()
```
## Setting the aesthetics
You can either set all the colours by hand, as seen in `pal3`, or use the "viridis" package to create a colour scale for you, as shown in `pal2`. For the UCDP data we used shades of red. The Geo-PKO data is mapped with viridis, which includes blue, green, and yellow.
```{r, warning=FALSE, message=FALSE}
pal2 <- colorBin((viridis::viridis(10)), GeoPKO_dataUCDP$ave.no.troops, bins = c(1, 50, 100, 500, 1000, 2000, 4000, 8000))
pal3 <- colorBin(c("#700524", "#8d072e", "#981f42", "#ed4d3a", "#af516c", "#d19bab", "#dcb4c0"),
UCDP_dataframe$best,
bins = c(1, 50, 100, 500, 1000, 2000, 4000, 10000, Inf)
)
```
## Mapping UCDP data with Geo-PKO
Just as we used leaflet for the VIEWS map, we do the same here. Note that in this case we did not merge the two datasets into one dataframe. When hovering over the circles, more information will be provided on either the UN peacekeeping deployment or on the UCDP conflict-related deaths. It is possible to use the PRIO-grid ID instead, and both datasets include this variable.
```{r, warning=FALSE, message=FALSE}
UCDP_Overview_Map <- leaflet() %>%
addTiles(options = providerTileOptions(noWrap = TRUE)) %>%
addMeasure(position = "bottomleft", primaryLengthUnit = "kilometers") %>% # Adds a widget that can measure distances between two places to the map
clearMarkers() %>%
clearShapes() %>%
addLegend("topright",
pal = pal3,
values = UCDP$best,
title = "Fatalities",
opacity = 1
) %>%
addLegend("topright",
pal = pal2,
values = GeoPKO_dataUCDP$ave.no.troops,
title = "Peacekeepers",
opacity = 1
) %>%
addLayersControl(
baseGroups = c("2019", "2018", "2015", "2010", "2005", "2000", "1995"),
options = layersControlOptions(collapsed = FALSE), position = "topleft"
) %>%
addCircleMarkers(
data = (GeoPKO2019 <- GeoPKO_dataUCDP %>% filter(year == 2019)),
color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
opacity = 0.15, fillOpacity = 0.5,
lng = ~longitude, lat = ~latitude, group = "2019",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO2019$mission,
"<br/><strong>Location:</strong>", GeoPKO2019$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO2019$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP2019 <- UCDP_dataframe %>% filter(year == 2019)),
lng = ~longitude, lat = ~latitude,
color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "2019",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP2019$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP2019$best,
"<br/><strong>Civilian deaths:</strong>", UCDP2019$deaths_civilians
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (GeoPKO2018 <- GeoPKO_dataUCDP %>% filter(year == 2018)),
color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
opacity = 0.15, fillOpacity = 0.5,
lng = ~longitude, lat = ~latitude, group = "2018",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO2018$mission,
"<br/><strong>Location:</strong>", GeoPKO2018$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO2018$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP2018 <- UCDP_dataframe %>% filter(year == 2018)),
lng = ~longitude, lat = ~latitude,
color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "2018",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP2018$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP2018$best,
"<br/><strong>Civilian deaths:</strong>", UCDP2018$deaths_civilians
) %>% lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (GeoPKO2015 <- GeoPKO_dataUCDP %>% filter(year == 2015)),
color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
opacity = 0.15, fillOpacity = 0.5,
lng = ~longitude, lat = ~latitude, group = "2015",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO2015$mission,
"<br/><strong>Location:</strong>", GeoPKO2015$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO2015$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP2015 <- UCDP_dataframe %>% filter(year == 2015)),
lng = ~longitude, lat = ~latitude,
color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "2015",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP2015$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP2015$best,
"<br/><strong>Civilian deaths:</strong>", UCDP2015$deaths_civilians
) %>% lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (GeoPKO2010 <- GeoPKO_dataUCDP %>% filter(year == 2010)),
color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
opacity = 0.15, fillOpacity = 0.5,
lng = ~longitude, lat = ~latitude, group = "2010",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO2010$mission,
"<br/><strong>Location:</strong>", GeoPKO2010$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO2010$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP2010 <- UCDP_dataframe %>% filter(year == 2010)),
lng = ~longitude, lat = ~latitude,
color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "2010",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP2010$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP2010$best,
"<br/><strong>Civilian deaths:</strong>", UCDP2010$deaths_civilians
) %>% lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (GeoPKO2005 <- GeoPKO_dataUCDP %>% filter(year == 2005)),
color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
opacity = 0.15, fillOpacity = 0.5,
lng = ~longitude, lat = ~latitude, group = "2005",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO2005$mission,
"<br/><strong>Location:</strong>", GeoPKO2005$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO2005$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP2005 <- UCDP_dataframe %>% filter(year == 2005)),
lng = ~longitude, lat = ~latitude,
color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "2005",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP2005$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP2005$best,
"<br/><strong>Civilian deaths:</strong>", UCDP2005$deaths_civilians
) %>% lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (GeoPKO2000 <- GeoPKO_dataUCDP %>% filter(year == 2000)), color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
opacity = 0.15, fillOpacity = 0.5,
lng = ~longitude, lat = ~latitude, group = "2000",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO2000$mission,
"<br/><strong>Location:</strong>", GeoPKO2000$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO2000$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP2000 <- UCDP_dataframe %>% filter(year == 2000)),
lng = ~longitude, lat = ~latitude,
color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "2000",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP2000$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP2000$best,
"<br/><strong>Civilian deaths:</strong>", UCDP2000$deaths_civilians
) %>% lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (GeoPKO1995 <- GeoPKO_dataUCDP %>% filter(year == 1995)), color = ~ pal2(ave.no.troops), radius = ~ (ave.no.troops)^(1 / 3),
lng = ~longitude, lat = ~latitude,
opacity = 0.15, fillOpacity = 0.5,
group = "1995",
label = paste(
"<strong>UN Peacekeeping Site<br/>Mission:</strong>", GeoPKO1995$mission,
"<br/><strong>Location:</strong>", GeoPKO1995$location,
"<br/><strong>Troops Deployed:</strong>", GeoPKO1995$ave.no.troops
) %>%
lapply(htmltools::HTML)
) %>%
addCircleMarkers(
data = (UCDP1995 <- UCDP_dataframe %>% filter(year == 1995)),
lng = ~longitude, lat = ~latitude, color = ~ pal3(best), radius = ~ (best)^(1 / 3),
opacity = 0.05, fillOpacity = 0.4,
group = "1995",
label = paste(
"<strong>UCDP Reported Fatalities<br/>Location:</strong>", UCDP1995$where_coordinates,
"<br/><strong>Total deaths:</strong>", UCDP1995$best,
"<br/><strong>Civilian deaths:</strong>", UCDP1995$deaths_civilians
) %>% lapply(htmltools::HTML)
)
# to save as HTML, you can use the following code:
# saveWidget(UCDP_Overview_Map, file="geopko&ucdp - geopko.html")
# Shows the map
UCDP_Overview_Map
```
And here we have it again: an interactive map to view peacekeeping deployments, in a few selected years, and conflict-related deaths within that same year. We opted to allow the user to select different years to see how both the numbers and locations of both datasets change over time.
## Merging the UCDP and Geo-PKO data
If you do want to combine the two datasets into one dataframe, there are different ways to do so. As shown with the VIEWS data, you can merge the datasets based on certain variables using "full_join", causing the two datasets to be combined in one file. This creates a dataframe in which the variables of one of the dataset occur next to the other. This can be used for the UCDP data as well. However, you can also merge datasets "under" each other. For the UCDP we wanted to show this second way of merging. Variables that are the same between the two datasets might go by different names, which is why some of the UCDP variables are renamed so that they are in line with the Geo-PKO variables. The newly combined dataset will first show all the UCDP rows, and under these the Geo-PKO rows will be "pasted".
Merging can be useful for all kinds of reasons, such as statistical analysis.
```{r}
# Rename variables you want to merge
# UCDP_dataframeMerge = UCDP_dataframe %>% rename (location=where_coordinates)
# Merge the datasets
# Combined_UCDP_GeoPKO<- bind_rows(UCDP_dataframeMerge, GeoPKO_dataUCDP)
```