Last updated: 2020-12-09

Checks: 7 0

Knit directory: GeoPKO/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200629) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 3059f09. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Unstaged changes:
    Modified:   analysis/_site.yml

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/merge.Rmd) and HTML (docs/merge.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 3059f09 Nguyen Ha 2020-12-09 merged, also fixed outwidth
html 3059f09 Nguyen Ha 2020-12-09 merged, also fixed outwidth
Rmd d436446 Tanushree Rao 2020-12-09 fixing issues with old and new merge page
Rmd 7a7271b Nguyen Ha 2020-12-09 merging gallery
Rmd 3c91f39 Nguyen Ha 2020-12-09 commit before pulling to build
html 3c91f39 Nguyen Ha 2020-12-09 commit before pulling to build
Rmd 6a20fd9 Lou van Roozendaal 2020-12-04 update global animated map
html c0b0ce3 Nguyen Ha 2020-12-03 Build site.
Rmd ee18491 Nguyen Ha 2020-12-03 minor edit
html a966566 Nguyen Ha 2020-12-03 Build site.
Rmd eafa002 Nguyen Ha 2020-12-03 adapting to new dataset version
Rmd 5502ba6 Lou van Roozendaal 2020-11-26 UpdateUCDP
Rmd c69de3a Tanushree Rao 2020-11-25 minor text updates + removing warning messages
Rmd 7cd68d8 Tanushree Rao 2020-11-25 minor edits, removing warning messages
html acee4ed Nguyen Ha 2020-11-25 Build site.
Rmd b6fea7a Nguyen Ha 2020-11-25 Revised viz, index, incorporated merge attempt 2.rmd
html 2011bda Nguyen Ha 2020-11-25 Build site.
Rmd 448b94c Nguyen Ha 2020-11-25 Revised viz, index, incorporated merge.rmd
Rmd ad652a3 Tanushree Rao 2020-11-24 changed ref to geopko so it opens with v1 data
Rmd 6d15379 Tanushree Rao 2020-11-24 updating merge page with new data
Rmd 2608fc0 Tanushree Rao 2020-09-10 merge file
Rmd 9174a7c Tanushree Rao 2020-09-09 adding kables
Rmd 113774e Tanushree Rao 2020-09-04 edits to data
Rmd 5afdf38 Tanushree Rao 2020-09-03 adding merge page

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.

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)

Geo-PKO x ViEWS

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.

library(readr)
geopko <- readr::read_csv("data/Geo_PKO_v2.0.csv") 
#unzip("data/ViEWS.zip", exdir="data/ViEWS")
predictors <- read.csv("data/ViEWS/ensemble_pgm.csv")

The Geo-PKO dataset includes detail on troop deployment numbers, types of troops, non-troop deployments, and contributing countries.

library(kableExtra)
kable(geopko[9546:9550,]) %>% kable_styling() %>%
  scroll_box(width = "100%", height = "200px")
source mission joined_date timepoint year month location geosplit country latitude longitude old_xy geocomment zone.de.confidence battalion company platoon other.size comment.on.unit no.troops rpf rpf.no inf inf.no fpu fpu.no res res.no fp fp.no eng sig trans riv he.sup sf med maint recon avia mp demining uav obs.base cantonment disarmament other.type armor he.sup.lw troop.type no.tcc nameoftcc_1 notroopspertcc_1 nameoftcc_2 notroopspertcc_2 nameoftcc_3 notroopspertcc_3 nameoftcc_4 notroopspertcc_4 nameoftcc_5 notroopspertcc_5 nameoftcc_6 notroopspertcc_6 nameoftcc_7 notroopspertcc_7 nameoftcc_8 notroopspertcc_8 nameoftcc_9 notroopspertcc_9 nameoftcc_10 notroopspertcc_10 nameoftcc_11 notroopspertcc_11 nameoftcc_12 notroopspertcc_12 nameoftcc_13 notroopspertcc_13 nameoftcc_14 notroopspertcc_14 nameoftcc_15 notroopspertcc_15 nameoftcc_16 notroopspertcc_16 nameoftcc_17 notroopspertcc_17 unpol.dummy unmo.dummy coding quality for UNMO (1=unsure; 0=perfectly fine) hq lo jmco security.group.dummy comments cow_code gnwo tcc1 tcc2 tcc3 tcc4 tcc5 tcc6 tcc7 tcc8 tcc9 tcc10 tcc11 tcc12 tcc13 tcc14 tcc15 tcc16 tcc17 adm1.id adm1.name prioid iso3c Month MonthName
Map no. 4249 Rev. 08 UNMIS 2007: August 2007 August 2007 8 Bentiu 0 Sudan 9.233333 29.83333 NA GNS has two locations pointing to basically the same place. I took the coords for “seat of first-order admin division”, rahter than “populated place”, both are in line with GE. Also, today’s south sudan NA 0 1 0 0 NA 150 NA NA 1 150 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA NA NA 0 0 NA 1 1 India 150 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 0 1 0 0 0 FALSE 0 NA 625 625 750 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 622 Unity 142980 SDN 8 August
Map no. 4249 Rev. 08 UNMIS 2007: August 2007 August 2007 8 Bor 0 Sudan 6.205931 31.55633 NA GNS has two locations, the “seat of first-order admin division” pointing to location of Google Earth by same name, as well as corresponding to source map, hence that one coded. Also, today’s south sudan NA 0 0 0 0 NA 0 NA NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA NA NA 0 0 NA 0 0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 0 1 0 0 0 FALSE 0 NA 625 625 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 621 Jungoli 138664 SDN 8 August
Map no. 4249 Rev. 08 UNMIS 2007: August 2007 August 2007 8 Dilling 0 Sudan 12.050000 29.65000 NA NA NA 0 0 0 0 NA 0 NA NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA NA NA 0 0 NA 0 0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 0 1 0 0 0 FALSE 0 NA 625 625 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 720 South Kordufan 147300 SDN 8 August
Map no. 4249 Rev. 08 UNMIS 2007: August 2007 August 2007 8 Ed Damazin 0 Sudan 11.789100 34.35920 NA NA NA 1 4 0 0 NA 1250 NA NA 1 650 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 NA NA NA 0 0 NA 1, 2, 4, 11, 14 1 Pakistan 1250 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 0 1 0 2 0 FALSE 0 NA 625 625 770 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 287 Blue Nile 146589 SDN 8 August
Map no. 4249 Rev. 08 UNMIS 2007: August 2007 August 2007 8 El Obeid 0 Sudan 13.183333 30.21667 NA NA NA 0 1 0 0 NA 150 NA NA 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NA NA NA 1 0 NA 99 0 unknown 150 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 0 0 NA 0 0 FALSE 0 “other” troop type refers to LOG company, unknown TCC 625 625 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 721 North Kordufan 148741 SDN 8 August

Filtering, joining and subsetting the datasets at the PRIO-grid level

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.

kable(predictors[90545:90550,]) %>% kable_styling() %>%
  scroll_box(width = "100%", height = "200px")
month_id pg_id average_allwthematic_sb average_allwthematic_ns average_allwthematic_os
90545 494 141560 0.0056672 0.0040548 0.0049985
90546 494 141561 0.0054137 0.0032145 0.0038274
90547 494 141562 0.0115811 0.0073864 0.0045633
90548 494 141563 0.0093885 0.0043294 0.0027875
90549 494 141564 0.0085510 0.0184678 0.0043437
90550 494 141565 0.0098269 0.0046215 0.0037409

The Geo-PKO dataset we’re working with includes data from previous years, but for this visualisation, we will only use the latest year (2019). First, we need to filter the data to include only that period. This way we’ll be looking at deployment status against projected conflict risk from the end of that period until three years from that period. 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 merge the datasets. In addition to filtering for the time period we want, we will also calculate the average number of troops deployed over that time period.

# filtering for troop deployments over 2019

geopko2 <- geopko %>%
  select(mission, year, month, prioid, no.troops, country, location, latitude, longitude) %>%
  mutate_at(vars(longitude, latitude, year, month, no.troops), as.numeric) %>%
  filter(year==2019)

geopko2$no.troops <- as.numeric(geopko2$no.troops)

# calculating an average number of troops

geopko3 <- geopko2 %>% 
  group_by(prioid) %>%
  dplyr::mutate(no.troops = mean(no.troops, na.rm=TRUE)) %>%
  ungroup() %>%
  filter (! duplicated(no.troops)) %>% 
  mutate(no.troops=round(no.troops))

Here, we also calculate the average conflict risk (state-based, non-state, and one-sided) for each location.

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(average_allwthematic_sb))

Finally, we merge the two datasets.

# merging geopko with conflict forecast data

geopko3$pg_id <- geopko3$prioid

priogriddf <- full_join(
  geopko3, predictors2,
  by = c("pg_id"), 
  na.rm = TRUE)

Merging the data and preparing 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.

shapefile <- rgdal::readOGR("data/ViEWS/priogrid.geojson")
OGR data source with driver: GeoJSON 
Source: "C:\Users\Nguyen Ha\Documents\DPCR\GeoPKO\Pages\GeoPKO\data\ViEWS\priogrid.geojson", layer: "priogrid"
with 64818 features
It has 1 fields

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.

# 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.

kable(shapefile.df@data[356:360,]) %>% kable_styling() %>%
  scroll_box(width = "100%", height = "200px")
pg_id id mission year month prioid no.troops country location latitude longitude month_id average_allwthematic_sb average_allwthematic_ns average_allwthematic_os
356 89685 3245 NA NA NA NA NA NA NA NA NA 486 0.0024289 0.0015213 0.0013923
357 89686 3246 NA NA NA NA NA NA NA NA NA 486 0.0029618 0.0021277 0.0020474
358 89687 3247 NA NA NA NA NA NA NA NA NA 486 0.0026179 0.0018690 0.0020587
359 89688 3248 NA NA NA NA NA NA NA NA NA 486 0.0023497 0.0017310 0.0018626
360 89689 3249 NA NA NA NA NA NA NA NA NA 486 0.0023957 0.0016043 0.0016756

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.

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. Simple markers show where troops are deployed. Troop deployment numbers are included as labels, which you can see for each square on hover.

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 = FALSE
    )
  ) %>%
  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 = FALSE
    )
  ) %>%
  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 = FALSE
    )
  ) %>%
  addCircleMarkers((data <- shapefile.df@data$no.troops > 0),
    lat = ~latitude, lng = ~longitude,
    weight = 1, radius = 2, fillOpacity = 0.6, color = "darkblue"
  ) %>%
  addPolygons(
    color = "#444444", weight = 0.1, smoothFactor = 0.5,
    opacity = 0.0, fillOpacity = 0.0,
    fillColor = ~ pal(shapefile.df@data$no.troops),
    label = paste("Troops Deployed: ", shapefile.df@data$no.troops),
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 8px", color = "blue"),
      textsize = "15px", direction = "auto"
    ),
    highlightOptions = highlightOptions(
      color = "white", weight = 2,
      bringToFront = FALSE
    )
  ) %>%
  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"),
    options = layersControlOptions(collapsed = FALSE)
  )

map <- map %>% htmlwidgets::prependContent(html_fix) # legend NA fix

# to save as HTML, you can use the following code:
# saveWidget(map, file="pkoviews - priogrid.html")

map

And here we have it: an interactive map to view the latest peacekeeping data and projected conflict risk over the next 36 months. 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.

# 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 might 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.

UCDP <- read_csv("data/UCDP/ged201.csv")
kable(UCDP[9546:9550,]) %>% kable_styling() %>%
  scroll_box(width = "100%", height = "200px")
year longitude latitude where_coordinates best deaths_civilians
2019 68.23228 33.60806 Dara Qayaq river 2 0
2019 63.11753 31.91940 Rakin village 1 0
2019 65.87257 36.30936 Khanaqa village 7 0
2019 69.42800 37.41980 Qara Tapa village 17 0
2019 70.21723 33.46187 Babrak Tana ruin 6 6

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.

# 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.

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.

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")

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. Select different years to see how both the numbers and locations of both datasets have changed over time.


sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=English_Sweden.1252  LC_CTYPE=English_Sweden.1252   
[3] LC_MONETARY=English_Sweden.1252 LC_NUMERIC=C                   
[5] LC_TIME=English_Sweden.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] kableExtra_1.1.0        readr_1.3.1             leaflet.providers_1.9.0
 [4] htmlwidgets_1.5.1       htmltools_0.5.0         rmapshaper_0.4.4       
 [7] RJSONIO_1.3-1.4         rjson_0.2.20            plyr_1.8.6             
[10] maptools_1.0-2          spdep_1.1-5             spData_0.3.8           
[13] sf_0.9-5                leaflet_2.0.3           ggplot2_3.3.2          
[16] rgdal_1.5-16            broom_0.7.0             geojsonio_0.9.2        
[19] tidyr_1.1.1             sp_1.4-2                dplyr_1.0.2            
[22] workflowr_1.6.2        

loaded via a namespace (and not attached):
 [1] nlme_3.1-148       fs_1.5.0           RColorBrewer_1.1-2 webshot_0.5.2     
 [5] httr_1.4.2         gmodels_2.18.1     rprojroot_1.3-2    tools_4.0.2       
 [9] backports_1.1.7    R6_2.4.1           KernSmooth_2.23-17 rgeos_0.5-3       
[13] DBI_1.1.0          lazyeval_0.2.2     colorspace_1.4-1   raster_3.3-13     
[17] withr_2.2.0        gridExtra_2.3      tidyselect_1.1.0   curl_4.3          
[21] compiler_4.0.2     git2r_0.27.1       rvest_0.3.6        expm_0.999-5      
[25] xml2_1.3.2         scales_1.1.1       classInt_0.4-3     stringr_1.4.0     
[29] digest_0.6.25      foreign_0.8-80     rmarkdown_2.3      pkgconfig_2.0.3   
[33] highr_0.8          jsonvalidate_1.1.0 rlang_0.4.7        rstudioapi_0.11   
[37] httpcode_0.3.0     farver_2.0.3       generics_0.0.2     jsonlite_1.7.1    
[41] crosstalk_1.1.0.1  gtools_3.8.2       magrittr_1.5       Matrix_1.2-18     
[45] Rcpp_1.0.5         munsell_0.5.0      viridis_0.5.1      lifecycle_0.2.0   
[49] stringi_1.4.6      whisker_0.4        yaml_2.2.1         MASS_7.3-52       
[53] jqr_1.1.0          grid_4.0.2         gdata_2.18.0       promises_1.1.1    
[57] crayon_1.3.4       deldir_0.2-3       lattice_0.20-41    splines_4.0.2     
[61] geojson_0.3.4      hms_0.5.3          knitr_1.29         pillar_1.4.6      
[65] boot_1.3-25        geojsonlint_0.4.0  codetools_0.2-16   LearnBayes_2.15.1 
[69] crul_1.0.0         glue_1.4.1         evaluate_0.14      V8_3.2.0          
[73] vctrs_0.3.2        httpuv_1.5.4       gtable_0.3.0       purrr_0.3.4       
[77] xfun_0.16          e1071_1.7-3        coda_0.19-4        later_1.1.0.1     
[81] viridisLite_0.3.0  class_7.3-17       tibble_3.0.3       units_0.6-7       
[85] ellipsis_0.3.1