R tool for
geographically analysing
ACLED data.
The Armed Conflict Location & Event Data Project (ACLED) is a disaggregated data collection
, analysis
, and crisis mapping
project
ACLED collects real-time data on the locations, dates, actors, fatalities, and types of all reported political violence and protest events around the world.
Install the latest release version of required packages from CRAN with :
install.packages(c('acled.api','dplyr', 'tibble', 'janitor', 'plotly', 'ggplot2'))
install.packages(c("sf", "leaflet", "leaflet.providers", "leaflet.opacity", "cartography"))
Call the library functions from the installed packages as follows:
ACLED API
library(acled.api)
Tools for data manipulation feature engineering:
library(dplyr)
library(tibble)
library(janitor)
Summary visuals
library(plotly)
library(ggplot2)
library(RColorBrewer)
Spatial Analysis and Visuals
library(sf)
library(tmap)
library(leaflet)
library(tmaptools)
library(cartography)
library(leaflet.opacity)
library(leaflet.providers)
Using Plotly
R package for summary visuals we would also want to save the static images.
Set the environment variables in the R session using Sys.setenv()
.
Sys.setenv("plotly_username" = "Musebe")
Sys.setenv("plotly_api_key" = "*********")
Export ACLED data to R usin the ACLED API:
Crime_in_Zimababwe <- acled.api(
email.address = "xxxx",
access.key = "xxxx",
country = "Zimbabwe",
start.date = "2005-01-01",
end.date = "2021-07-01",
add.variables = c("latitude","longitude", "geo_precision", "time_precision")
The above function imitates the ACLED data export tool. The two credentials required for the API to function are the email adress and the access key which are availed upon subcribing to the platform.
Sample view of the data:
iso3 | year | event_date | source | admin1 | admin2 | location | event_type | sub_event_type | interaction | fatalities | timestamp | latitude | longitude | geo_precision | time_precision |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ZWE | 2021 | 28-Jun-21 | Zimbabwean | Matabeleland North | Hwange Urban | Hwange | Protests | Protest with intervention | 16 | 0 | 1625510722 | -18.3693 | 26.5019 | 2 | 2 |
ZWE | 2021 | 18-Jun-21 | Zim Eye | Harare | Harare Urban | Harare | Violence against civilians | Attack | 17 | 0 | 1625510722 | -17.8277 | 31.0534 | 1 | 1 |
ZWE | 2021 | 16-Jun-21 | New Zimbabwe | Mashonaland West | Kadoma Urban | Kadoma | Protests | Peaceful protest | 60 | 0 | 1625510721 | -18.35 | 29.9167 | 1 | 1 |
ZWE | 2021 | 9-Jun-21 | Bulawayo24 | Bulawayo | Bulawayo | Bulawayo | Riots | Mob violence | 15 | 0 | 1624310472 | -20.15 | 28.58 | 1 | 1 |
ZWE | 2021 | 7-Jun-21 | Chronicle (Zimbabwe) | Bulawayo | Bulawayo | Bulawayo | Strategic developments | Looting/property destruction | 60 | 0 | 1624310472 | -20.15 | 28.58 | 1 | 1 |
Adding a column time past since 1979-01-01
. Also for purpose of summarizing data in the year create the day of the week
and month
variable. Both of them from the event_date
variable.
NB: Little cleaning is required for the ACLED data as most of the data is already sorted and ready for analysis.
Crime_in_Zimbabwe <- Crime_in_Zimbabwe %>%
add_column(
# time
time = format(as.POSIXct(
Crime_in_Zimbabwe$timestamp, origin="1970-01-01"), format = "%H:%M:%S"),
# day of the week
dow = weekdays(as.Date(Crime_in_Zimbabwe$event_date), abbreviate = T),
#Month of the Year
month = months(as.Date(Crime_in_Zimbabwe$event_date), abbreviate = TRUE)
)
Sample visuals extracted from the data are as follows:
Harare faces high crime activity than other locations in the country.
Harare province has the highest crisis rate. This is relative with Harare town being in the same province.
Distribution of crime activity:
The visual suggests negative correlation between male population and the crime rate in all the provinces. An outlier is seen un the Harare province. This
Geneat visuals of the administrative boundaries of Zimbabwe can be produced by:
leaflet() %>%
addProviderTiles(providers$OpenStreetMap.HOT) %>%
addPolygons(data = level_3 , # borders of all wards
color = "grey",
fill = NA,
weight = 0.8) %>%
addPolygons(data = level_2 , # borders of all districts
color = "blue",
fill = NA,
weight = 1) %>%
addPolygons(data = level_1 , # borders of all provinces
color = "red",
fill = NA,
weight = 1.5) %>%
addPolygons(data = zim , # borders of the Country
color = "grey",
fill = NA,
weight = 4)
Example:
By leaflet
package(left image) & cartography
package:
The sample data used here belongs to and has been extracted from ACLED.