Rev. | f90fbb71566498e0bdc70b577b7cbfee2eb603e0 |
---|---|
大小 | 3,639 字节 |
时间 | 2021-08-06 07:06:07 |
作者 | Lorenzo Isella |
Log Message | I fixed the problem of the internal border in Cyprus. |
rm(list=ls())
library(tidyverse)
library(rnaturalearth)
library(sf)
library(patchwork)
library(RJSDMX)
library(janitor)
library(viridis)
source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R")
##########################################################
ww_ini <- ne_countries(scale = "medium",
type = 'countries',
returnclass = "sf")
bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
returnclass = "sf")
target_crs <- '+proj=eqearth +wktext'
disp_win_wgs84 <- st_sfc(st_point(c(-20, 30)), st_point(c(45, 73)),
crs = 4326)
ww_ini_eqea <- st_transform(ww_ini, target_crs)
## cities_sf_eqea <- st_transform(cities_sf, target_crs)
## line_eqea <- st_transform(line, target_crs)
disp_win_eqea <- st_transform(disp_win_wgs84, target_crs)
print(st_coordinates(disp_win_eqea))
gpl5 <- ggplot(ww_ini_eqea) +
geom_sf() +
## # Add cities
## geom_sf(data = cities_sf_eqea, color = "blue") +
## # Now the line
## geom_sf(data = line_eqea, color = "red") +
# Limit the map
coord_sf(
xlim = st_coordinates(disp_win_eqea)[, "X"],
ylim = st_coordinates(disp_win_eqea)[, "Y"],
) +
theme_minimal()
ggsave("simple_europe_equal_earth_segment_stack.pdf", gpl5, width=5,height=5)
df_score <- readRDS("scoreboard.RDS")
df_stat <- df_score %>%
group_by(year, member_state) %>%
summarise(expenditure=sum(amount_spent_aid_element_in_eur_million, na.rm=T)) %>%
ungroup
year_last <- df_stat %>%
pull(year) %>%
max
df_last <- df_stat %>%
filter(year==year_last)
query1 <- "tec00001/A.B1GQ.CP_MEUR."
gdp <- estat_retrieval(query1)
gdp_sel <- gdp %>%
clean_names() %>%
filter(time_period==year_last) %>%
select(obs_value, geo)
df_map <- df_last %>%
left_join(y=iso_map_eu28, by=c("member_state"="iso3") ) %>%
left_join(y=gdp_sel, by=c("iso2"="geo")) %>%
mutate(share=expenditure/obs_value*100) %>%
select(member_state, share)
## See https://stackoverflow.com/questions/68672575/r-rnaturalearth-and-sf-remove-a-single-border-from-map
cyprus <- ww_ini_eqea %>%
mutate(iso_a3=replace(iso_a3, name=="N. Cyprus", "CYP" )) %>%
select(iso_a3) %>%
filter(iso_a3 %in% c("CYP")) %>%
group_by(iso_a3) %>%
summarise()
ww2 <- ww_ini_eqea %>%
mutate(iso_a3=replace(iso_a3, name=="N. Cyprus", "CYP" )) %>%
select(iso_a3) %>%
filter(iso_a3 %!in% c("CYP") ) %>%
bind_rows(cyprus) %>%
left_join(y=df_map, by= c("iso_a3"="member_state")) %>%
mutate(share=round(share,2)) %>%
mutate(share_cut=cut(share, breaks=seq(0.2, 1.8, by=0.4))) %>%
mutate(share_cut=as.character(share_cut))
my_pal <- viridis(5)[1:4]
my_breaks <- ww2 %>%
select(share_cut) %>%
filter(!is.na(share_cut)) %>%
select(share_cut) %>%
arrange(share_cut) %>%
pull(share_cut) %>%
unique %>%
rev
gpl_fin <- ggplot(ww2) +
## geom_sf() +
geom_sf(aes(fill=share_cut), col = "black", lwd = 0.3 )+
## # Add cities
## geom_sf(data = cities_sf_eqea, color = "blue") +
## # Now the line
## geom_sf(data = line_eqea, color = "red") +
# Limit the map
coord_sf(
xlim = st_coordinates(disp_win_eqea)[, "X"],
ylim = st_coordinates(disp_win_eqea)[, "Y"],
expand=T
) +
theme_minimal()+
scale_fill_manual("Aid as % of GDP", values = my_pal,
breaks=my_breaks,
## na.translate=F,
na.value = "grey50")
ggsave("scoreboard_map.pdf", gpl_fin, width=5,height=5)
print("So far so good")