Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # arc de crise Afrique
- ged171 <- read.csv("data/ged171.csv")
- #selection pays arc de crise Afrique.
- nigeria<- ged171[ged171$country=="Nigeria",]
- mali <- ged171[ged171$country=="Mali",]
- niger <- ged171[ged171$country=="Niger",]
- chad <- ged171[ged171$country=="Chad",]
- sudan <- ged171[ged171$country=="Sudan",]
- south_sudan <- ged171[ged171$country=="South Sudan",]
- ethiopia <- ged171[ged171$country=="Ethiopia",]
- eritrea<- ged171[ged171$country=="Eritrea",]
- libya<- ged171[ged171$country=="Libya",]
- algeria<- ged171[ged171$country=="Algeria",]
- egypt<- ged171[ged171$country=="Egypt",]
- somalia<- ged171[ged171$country=="Somalia",]
- #fusion des lignes de chaque tableaux pour créer un tableau unique.
- arc_de_crise <- rbind(niger,mali,nigeria,chad,sudan,south_sudan,ethiopia,eritrea,
- libya,algeria,egypt,somalia)
- # load Packages
- library(sf)
- library(sp)
- library(cartography)
- library(rnaturalearth)
- library("SpatialPosition")
- #importation du fond de carte
- country <- ne_countries(scale = 110, type = "sovereignty", returnclass = "sf")
- afr_ucdp <- ne_countries(continent = 'africa',scale = 110, type = "sovereignty", returnclass = "sf")
- projrob <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
- afr_ucdp <- st_transform(x = afr_ucdp, crs = projrob)
- projrob <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"
- country <- st_transform(x = country, crs = projrob)
- # Tranformation du data.frame nigeria en couche de points (objet sf)
- arc_de_crise <- st_as_sf(arc_de_crise, coords = c("longitude", "latitude"),remove = F,
- crs = 4326)
- # Changer la projection de la couche des conflits wgs84 => robinson
- arc_de_crise<- st_transform(x = arc_de_crise, crs = projrob)
- par(mar = c(0,0,1.2,0))
- # Affichage des points sur la carte. (carte semi de points)
- opar <- par(mar = c(0,0,1.2,0))
- plot(st_geometry(afr_ucdp),add=F, col = NA, border = NA, bg = "lightblue")
- plot(st_geometry(afr_ucdp), col = "grey90", border = NA, add=T)
- plot(st_geometry(afr_ucdp), add=T, col ="lightyellow", lwd = 0.5, border = "grey")
- plot(st_geometry(arc_de_crise), col="#96000040", cex = .5, pch = 16, add=TRUE)
- # pour travailler sur le nombre d'evenements
- arc_de_crise$cpt <- 1
- # Créer la grille de points
- mygrid <- CreateGrid(w = as(afr_ucdp,"Spatial"), resolution = 100000)
- #years <- list(c(1989:1995),c(1996:2002), c(2003:2009), c(2010:2016))
- # selectionner les evt des 2013 à 2016
- evtx <- arc_de_crise[arc_de_crise$year %in% c(1989:2016),]
- mymat <- CreateDistMatrix(knownpts = as(evtx,"Spatial"), unknownpts = mygrid)
- # calcul des potentiels
- mystewart <- stewart(knownpts = as(evtx,"Spatial"), unknownpts = mygrid,
- matdist = mymat, varname = "best",
- typefct = "exponential", span = 75000,
- beta = 2, mask = as(afr_ucdp, "Spatial"))
- # transformation en Raster
- ras <- rasterStewart(mystewart)
- # chouix des bornes de classes
- bb <- c(1,2,5,10,20,50,100,200,500,1000, 2000, 5000, 10000, 20000, 50000)
- #ou bb<- c(25,50,100,200,500,1000, 2000, 5000, 10000, 20000, 50000)
- # transformation du raster en polygones
- contourpoly <- rasterToContourPoly(r = ras,breaks = bb,
- mask = as(afr_ucdp, "Spatial"))
- plot(contourpoly)
- opar <- par(mar = c(0,0,1.2,0))
- plot(afr_ucdp$geometry, add=F, col = NA, border = NA, bg = "lightblue")
- plot(country$geometry, col = "grey90", border = NA, add=T)
- plot(afr_ucdp$geometry, add=T, col ="lightyellow", lwd = 0.5, border = "grey")
- choroLayer(spdf = contourpoly,
- col = carto.pal("wine.pal", length(bb)-1),
- df = contourpoly@data,
- var = "center", legend.pos = c(-1294561, -3027262 ),
- breaks = bb, border = NA,
- lwd = 0.2,add=T,
- legend.title.txt = "Nb de morts\ndans les conflits",
- legend.values.rnd = 2)
- plot(afr_ucdp$geometry, border = "grey", add=T, lwd = 0.2)
- layoutLayer(title = "1989:2016", tabtitle = T, frame = F,scale = NULL)
Add Comment
Please, Sign In to add comment