-
Notifications
You must be signed in to change notification settings - Fork 0
/
GTM.Rmd
105 lines (90 loc) · 3 KB
/
GTM.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
---
output:
html_document:
toc: true
toc_float: true
toc_collapsed: true
toc_depth: 3
number_sections: false
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Guatemala hotspots
Climate-conflict intersection hotspots in Guatemala.
```{r k3, echo=FALSE, message=F, warning=F,comment=F}
library(terra)
library(tmap)
library(mapview)
library(geojsonio)
library(geojsonsf)
library(geodata)
library(sf)
library(tmap)
library(readxl)
root <- 'D:/OneDrive - CGIAR/Analysis/CSO/'
iso <- 'GTM'
conf <- geojsonio::geojson_sf(paste0(root,iso,'/clim_conflict_ips_overlays.geojson'))
conf <- conf[conf$label=="High conflict" ,]
k <- unique(conf$intersect_conf_clim)
k <- c(k[3],k[1],k[2])
#k <- c(k[1:4],k[9:12],k[5:8])
for(i in 1:length(k)){
conf$clust[conf$intersect_conf_clim==k[i]] <- i
}
#labs <- conf$intersect_conf_clim[!duplicated(conf$clust)]
labs <- gsub(" levels of|\\[|/.*", "", k)
conf$clust <- as.factor(conf$clust)
bdy1 <- geodata::gadm(country=iso, level=1, path=paste0(root,iso,'/'))
bdy1 <- sf::st_as_sf(bdy1)
bdy1 <- sf::st_cast(bdy1) # Removes duplicte labels
bdy2 <- geodata::gadm(country=iso, level=2, path=paste0(root,iso,'/'))
bdy2 <- sf::st_as_sf(bdy2)
bdy2 <- sf::st_cast(bdy2)
#bdy3 <- geodata::gadm(country=iso, level=3, path=paste0(root,iso,'/'))
#bdy3 <- sf::st_as_sf(bdy3)
library(sf)
conf <- st_intersection(conf,bdy2[c("NAME_1","NAME_2")])
conf$Department <- conf$NAME_1
conf$Municipality <- conf$NAME_2
names(conf)[7] <- 'Fatalities'
tmap_mode("view")
ken <- tm_shape(bdy1, name = 'Department')+
tm_borders() +
tm_shape(bdy2, name = 'Municipality')+
tm_borders() +
#tm_shape(bdy3, name = 'Ward')+
#tm_borders()+
tm_shape(conf, name = 'Conflict')+
tm_fill(col= "clust", palette="-YlOrRd", title = 'Climate-Conflict-Hotspots', labels=labs, popup.vars=c("Department","Municipality", "Fatalities", "climvar_medn_prec", "climvar_NDWS_median"))+
tm_view(view.legend.position =c("right", "top"))+
tm_format("World")
ken
```
```{r k4, include=FALSE}
tmap_mode("plot")
ken <- tm_shape(bdy1, name = 'Department')+
tm_borders(col='black') +
tm_text("NAME_1", size = 1, remove.overlap = TRUE)+
#tm_shape(bdy2, name = 'Municipality')+
#tm_borders() +
#tm_shape(bdy3, name = 'Ward')+
#tm_borders()+
tm_shape(conf, name = 'Conflict')+
tm_fill(col= "clust", palette="-YlOrRd", alpha=0.65, title = 'Climate-conflict hotspots', labels=labs)+
tm_compass(type = "8star", position = c("right", "top")) +
tm_scale_bar(breaks = c(0, 50, 100), text.size = 1,
position = c("right", "bottom"))+
tm_layout(legend.outside=F,
legend.width = 0.75,
legend.title.size= 1.3,
legend.text.size = 1.1,
legend.frame=F,
legend.just = c("left", "top"),
legend.position= c("left", "top"))
ken
tmap_save(ken, dpi= 600, height=8, width=10, units="in",
filename=paste0(root,iso,'/',iso,"_High_confict_climate_intersection.png"))
```