-
Notifications
You must be signed in to change notification settings - Fork 0
/
load-data.R
116 lines (96 loc) · 4.67 KB
/
load-data.R
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
105
106
107
108
109
110
111
112
113
114
115
library(tidyverse)
library(shiny)
library(sf)
library(scales)
library(RColorBrewer)
library(leaflet)
library(rmapshaper)
dat <- read.csv('data/master-df_final.csv')
clusters <- read.csv('data/cluster.csv')
clust.name <- read.csv('data/clus-new-order-typ.csv')
inddat <- read.csv('data/residual-ind-vals-LV9-final.csv')
indlab <- read.csv('data/indicator-labels.csv')
#world_simp <- ms_simplify(World, keep_shapes = T)
#st_write(world_simp, 'data/UIA_World_Countries_Boundaries/UIA_World_Countries_Boundaries_simp.gpkg', overwrite = T, append = F)
World <- st_read('data/UIA_World_Countries_Boundaries/UIA_World_Countries_Boundaries_simp.gpkg')
World$Country <- recode(World$Country, `Russian Federation` = 'Russia',
`Brunei Darussalam` = 'Brunei',
Comoros = 'Comores',
`Timor-Leste` = 'East Timor',
Somalia = 'Federal Republic of Somalia',
`Côte d'Ivoire` = 'Ivory Coast',
Mauritius = 'Republic of Mauritius')
toc_dat <- read.csv('data/Book3.csv') %>% st_as_sf(coords = c('X', 'Y'), crs = 4326) #%>% mutate(Ecosystem = factor(Ecosystem))
# rescale indicator data
max <- min(apply(inddat, 2, max))
min <- max(apply(inddat, 2, min))
inddat <- inddat %>%
mutate_all(funs(rescale(., to = c(min, max))))
# join country names to indicator data
inddat$ISO_SOV1 <- dat$ISO_SOV1
dtemp <- clusters %>%
rename(cluster = Cluster) %>%
right_join(inddat, by = 'ISO_SOV1') %>%
left_join(clust.name, by = 'cluster') %>%
distinct() %>%
left_join(select(dat, ISO_SOV1, Country), by = 'ISO_SOV1') %>%
rename(Cluster = fine.clust) %>%
select(-c(cluster, pal.fine)) %>%
pivot_longer(cols = OECD_sc:ramsar.manage, names_to = 'indicator', values_to = 'val') %>%
left_join(indlab, by = 'indicator')
# get full spatial df with model results and merge by country
dat2 <- dat %>%
left_join(clusters, by = 'ISO_SOV1') %>%
distinct() %>%
dplyr::rename(iso_a3 = ISO_SOV1) %>%
dplyr::rename(cluster = Cluster) %>%
left_join(clust.name, by = 'cluster') %>%
mutate('Enabling profile' = fine.clust)
world.clust <- World %>%
left_join(dat2, by = 'Country') %>%
filter(!is.na(pal.fine))
# colour palette
palset <- pal <- c("#88CCEE","#6699CC", "#44AA99", "#117733", "#CC6677","#882255")
pal <- colorFactor( # colour palette for blue forest projects
palette = palset,
domain = world.clust$`Enabling profile`)
pal2 <- colorFactor( # colour palette for blue forest projects
palette = c('darkgoldenrod1', 'midnightblue'),
domain = toc_dat$Ecosystem)
# pop-ups
pop_up <- st_drop_geometry(toc_dat) %>%
mutate(popup = paste0("<span style='font-size: 120%'><strong>", Ecosystem ,"</strong></span><br/>",
"<br/>",
"<strong>", "Enabling profile: ", "</strong>", Enabling.profile,
"<br/>",
"<br/>",
"<strong>", "Policy: ", "</strong>", Policy,
"<br/>",
"<strong>", "Regulation: ", "</strong>", Regulation,
"<br/>",
"<strong>", "Engagement: ", "</strong>", Engagement,
"<br/>",
"<br/>",
"<strong>", "Theory of change: ", "</strong>", Implementation.pathway,
"<br/>",
"<br/>",
"<strong>", "Case study example: ", "</strong>", Case.study)) %>%
pull(popup)
pop_up2 <- st_drop_geometry(world.clust) %>%
mutate(Enabling.profile = factor(`Enabling profile`)) %>%
left_join(distinct(mutate(select(st_drop_geometry(toc_dat), Enabling.profile, Policy, Regulation, Engagement), Enabling.profile = factor(Enabling.profile))), by = 'Enabling.profile') %>%
mutate(popup = paste0("<span style='font-size: 120%'><strong>", Country ,"</strong></span><br/>",
"<br/>",
"<strong>", "Enabling profile: ", "</strong>", `Enabling profile`,
"<br/>",
"<br/>",
"<strong>", "Policy: ", "</strong>", Policy,
"<br/>",
"<strong>", "Regulation: ", "</strong>", Regulation,
"<br/>",
"<strong>", "Engagement: ", "</strong>", Engagement)) #%>%
#pull(popup)
# vector of profile/country names
country <- c('Globe','Enabling profile 1', 'Enabling profile 2', 'Enabling profile 3',
'Enabling profile 4', 'Enabling profile 5', 'Enabling profile 6',
sort(as.character(unique(world.clust$Country))))