Skip to content

Instantly share code, notes, and snippets.

@dickoa
Last active February 20, 2022 19:06
Show Gist options
  • Save dickoa/6ba82330ec232d244013f9bfa39054c1 to your computer and use it in GitHub Desktop.
Save dickoa/6ba82330ec232d244013f9bfa39054c1 to your computer and use it in GitHub Desktop.
Mali violence map ACLED
library(tidyverse)
library(sf)
library(rgeoboundaries) ## remotes::install_github("wmgeolabs/rgeoboundaries")
library(racled) ## remotes::install_gitlab("dickoa/racled")
library(cowplot)
### Get Mali country boundaries
mli_adm0 <- gb_adm0("mali")
### Get Mali ACLED data
mli_acled <- read_acled("mali")
glimpse(mli_acled) ## check the data
## Create spatial objects, lumping event_type
mli_acled_pts <- mli_acled |>
filter(year >= 2013,
year <= 2021,
fatalities >= 1) |>
mutate(event_type2 = fct_lump(event_type,
n = 3,
other_level = "Other events")) |>
drop_na(longitude, latitude) |>
st_as_sf(coords = c("longitude", "latitude"),
crs = 4326)
## Color palette
pal <- c("Battles" = "#BF1154",
"Explosions/Remote violence" = "#DA7C5D",
"Violence against civilians" = "#F2D16D",
"Other events" = "#525A61")
### The chart
ggplot() +
geom_sf(data = mli_adm0) +
geom_sf(data = mli_acled_pts,
aes(size = fatalities,
fill = event_type2),
shape = 21,
stroke = 0.1,
alpha = 0.7) +
labs(title = "Violence in Mali since 2013",
subtitle = "Events resulting in more than one fatality",
caption = "Source: ACLED") +
scale_fill_manual("", values = pal,
guide = guide_legend(override.aes = list(size = 3))) +
scale_size(name = "Dead",
breaks = c(10, 157),
range = c(1, 4),
guide = guide_legend(title.position = "right")) +
facet_wrap(vars(fct_rev(as.factor(year)))) +
theme_map() +
theme(legend.position = "top",
legend.direction = "horizontal",
plot.caption = element_text(hjust = 0, vjust = 1),
plot.caption.position = "plot")
@Pete-254
Copy link

When I attempt to install remotes::install_github("dickoa/racled")

it returns Error: Failed to install 'unknown package' from GitHub:

Did I miss something?

@dickoa
Copy link
Author

dickoa commented Feb 20, 2022

Thanks a lot @Pete-254 . I meant "gitlab". I corrected it, let me know if it works for you.
You probably know it already but you'll need to register to use ACLED API, to have an API KEY (associated to an email)
https://acleddata.com/register/

With your key and email, just add this to your .Renviron

ACLED_EMAIL="[email protected]"
ACLED_ACCESS_KEY="xxxxxxxxxxxxxxxxx"

Hope it helps.
Thanks

@Pete-254
Copy link

Thanks @dickoa . I have done so, using my email and key and returns the following

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open URL 'https://api.acleddata.com/acled/read.csv?key=xxxx&email=xxxxk&limit=0&terms=accept&iso=404': HTTP status was '500 Internal Server Error'

using my email and key, I can however, download the data from https://acleddata.com/data-export-tool/ as a csv

I also tried the option in the instructions: You can also call the ACLED API directly. In order to retrieve data from the API, you must make a GET or POST request to the following URL: https://api.acleddata.com/acled/read/?key=****************1234&[email protected]

It returns
{"status":403,"success":false,"count":0,"error":{"status":403,"message":"Your account is restricted to only downloading the data via the Data Export Tool. Please contact [email protected] to discuss extending your access to the API."}}

@dickoa
Copy link
Author

dickoa commented Feb 20, 2022

Hi @Pete-254,
You should contact [email protected] to ask them if you can use your key to query it via the API. I remember that I had a similar issue, and they fixed it.

@Pete-254
Copy link

Hi @dickoa,
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment