-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap_crpd.R
More file actions
186 lines (166 loc) · 5.04 KB
/
Copy pathmap_crpd.R
File metadata and controls
186 lines (166 loc) · 5.04 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
crpd_colors <- c("Signed Convention" = "#FFCC67", "Signed Convention & Protocol" = "lightblue",
"Ratified Convention" = "#346699", "Ratified Convention & Protocol" = "#FF4001")
denmark_crpd <- dat_all |>
filter(country == "Denmark") |>
pull(crpd)
dat_all <- dat_all |>
add_row(
crpd = denmark_crpd, country = "Greenland"
)
library(rnaturalearth)
world <- ne_countries(returnclass = "sf")
dat_all <- dat_all |>
mutate(
crpd_label = case_match(
crpd,
"1" ~ "Signed Convention",
"2" ~ "Signed Convention & Protocol",
"3" ~ "Ratified Convention",
"4" ~ "Ratified Convention & Protocol"
) |>
factor(levels = names(crpd_colors))
)
# -------------------------------------------------------------------------
## Plotly is a headache..
# sfdat <- world |>
# left_join(
# dat_all, by = join_by(iso_a3_eh == iso3c)
# ) |>
# st_as_sf() |>
# filter(!is.na(geometry))
# plot_ly() |>
# # add_sf(
# # data = sfdat,
# # type = "scatter",
# # text = ~name,
# # ## Warning about markers...?
# # # mode = "markers",
# # split = ~name,
# # hoveron = "fills",
# # hoverinfo = "text",
# # color = ~crpd_label,
# # colors = crpd_colors,
# # stroke = NA,
# # alpha = 1,
# # legendgroup = ~name
# # # ,
# # # colorscale = crpd_colors
# # ) |>
# add_sf(
# data = sfdat,
# hovertext = "none",
# hoverinfo = "none",
# color = ~crpd_label,
# colors = crpd_colors,
# stroke = NA,
# alpha = 1
# ) |>
# # add_sf(
# # data = sfdat,
# # text = ~name,
# # split = ~name,
# # hovertext = "text",
# # hoverinfo = "text",
# # visible = FALSE
# # ) |>
# layout(
# title = "CRPD and Optional Protocol Signatures and Ratifications",
# geo = list(
# projection = list(type = "orthographic"),
# showframe = TRUE,
# showcoastlines = TRUE,
# coastlinecolor = "RebeccaPurple",
# lataxis = list(range = c(-59, 90))
# ),
# legend = list(
# orientation = "h",
# x = 0.5,
# xanchor = "center",
# y = 1.1, # Positions the legend above the top of the map
# yanchor = "top"
# )
# )
# # |>
# add_trace(
# text = ~name, # Assuming 'name' is the column with country names
# mode = 'text',
# textposition = 'middle center',
# textfont = list(color = 'black'),
# lon = ~lon,
# lat = ~lat
# )
# # |>
# # colorbar(
# # title = "CRPD Levels",
# # orientation = 'h', # Set the colorbar horizontally
# # x = 0.5, # Center the colorbar
# # xanchor = 'center', # Anchor the center at x
# # y = 1.05, # Position it above the top
# # yanchor = "bottom"
# # )
# GGplot ------------------------------------------------------------------
dat_all <- dat_all |>
mutate(
crpd_label = case_match(
crpd,
"1" ~ "Signed Convention",
"2" ~ "Signed Convention & Protocol",
"3" ~ "Ratified Convention",
"4" ~ "Ratified Convention & Protocol"
) |>
factor(levels = names(crpd_colors))
)
# reproject from longlat to robinson
world <- st_transform(world, "+proj=robin")
world <- world |>
mutate(center = st_centroid(geometry),
lon = st_coordinates(center)[,1],
lat = st_coordinates(center)[,2])
world <- world |>
filter(!is.na(name) & !name %in% c("Antarctica", "Fr. S. Antarctic Lands"))
denmark_greenland <- world |>
filter(name %in% c("Greenland", "Denmark"))
# Combine their geometries
combined_geometry <- st_union(denmark_greenland$geometry)
world <- world |>
mutate(geometry = if_else(name == "Denmark", combined_geometry, geometry)) |>
filter(name != "Greenland") |>
select(geometry, name, iso_a3_eh, lon, lat)
sfdat <- world |>
right_join(
dat_all, by = join_by(iso_a3_eh == iso3c)
) |>
st_as_sf() |>
filter(!is.na(geometry))
graticules <- sf::st_graticule(crs = "+proj=robin")
p <- ggplot(data = sfdat) +
# geom_sf(data = graticules, fill = "grey90", color = "white", alpha = 0.5) +
geom_sf(aes(fill = crpd_label),
# text = ~name,
# color = I("black"),
alpha = 1) +
scale_fill_manual(values = crpd_colors) +
labs(title = "CRPD and Optional Protocol Signatures and Ratifications", fill = "") +
theme(
legend.position = "top",
# Increase title text size significantly (adjust the size value as needed)
plot.title = element_text(hjust = 0.5, face = "bold", color = "#346699", size = 22),
# Increase legend (category) text size
legend.title = element_text(size = 16),
legend.text = element_text(size = 14),
panel.grid = element_line(color = "lightblue", linetype = 1),
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.title.y = element_blank(),
axis.ticks.x = element_blank()
)
p <- p +
geom_label_repel(
size = 2,
aes(x = lon, y = lat, label = name),
label.padding = 0.15,
box.padding = 0.15,
label.size = 0.05,
max.overlaps = 15
)
ggsave("www/map_crpd.png", p, width = 30, height = 15, dpi = 300)