Skip to content

Instantly share code, notes, and snippets.

@jmcastagnetto
Created March 11, 2022 21:17
Show Gist options
  • Save jmcastagnetto/04cf680d0623e05fe01dbaab76bce9a3 to your computer and use it in GitHub Desktop.
Save jmcastagnetto/04cf680d0623e05fe01dbaab76bce9a3 to your computer and use it in GitHub Desktop.
Map showing the asymmetric distribution of the ratio of excess deaths to COVID-19 deaths (2020-2021)
# Data source: http://ghdx.healthdata.org/record/ihme-data/covid_19_excess_mortality
library(tidyverse)
library(sf)
library(rnaturalearth)
library(ggridges)
library(patchwork)
world_map <- ne_countries(type = "countries", returnclass = "sf")
data <- read_csv(
"IHME_EM_COVID_19_2020_2021_DATA_Y2022M03D10.csv",
locale = locale(encoding = "iso-8859-1")
) %>%
filter(level == 3) %>% # country data
filter(measure_name == "ratio_excess_over_covid") %>%
select(
location_name,
measure_name,
mean_value,
lower_ci,
upper_ci
) %>%
mutate(
iso3c = countrycode::countrycode(
location_name,
origin = "country.name.en",
destination = "iso3c"),
ratio_class = cut(
mean_value,
breaks = c(-20, 0, 1, 2, 5, 10, 20, 200),
labels = c(
"< 0",
"(0, 1]",
"(1, 2]",
"(2, 5]",
"(5, 10]",
"(10, 20]",
"> 20"
),
right = TRUE,
ordered_result = TRUE
)
) %>%
left_join(
data.frame(
iso3c = rworldmap::countriesLow$ISO_A3,
x = rworldmap::countriesLow$LON,
y = rworldmap::countriesLow$LAT
),
by = "iso3c"
)
world_df <- world_map %>%
filter(sov_a3 != "ATA") %>% # remove Anctartica
left_join(
data,
by = c("iso_a3" = "iso3c")
) %>%
filter(!is.na(ratio_class))
map1 <- ggplot(
world_df
) +
geom_sf(aes(fill = ratio_class)) +
scale_fill_brewer(
name = "Ratio: ",
type = "seq", palette = "YlGnBu"
) +
coord_sf(crs = "+proj=moll") +
guides(
fill = guide_legend(nrow = 1)
) +
labs(
title = "Worldwide asymmetric distribution of excess deaths to COVID-19 deaths",
subtitle = "Data source: \"COVID-19 Excess Mortality Estimates 2020-2021\" (http://ghdx.healthdata.org/record/ihme-data/covid_19_excess_mortality)",
caption = "@jmcastagnetto, Jesus M. Castagnetto (2022-03-11)"
) +
theme_minimal() +
theme(
axis.text = element_blank(),
axis.ticks = element_blank(),
legend.position = "top",
plot.title = element_text(size = 28, face = "bold"),
plot.subtitle = element_text(size = 14, colour = "grey50"),
plot.caption = element_text(family = "Inconsolata", size = 14)
)
inset <- ggplot(
world_df,
aes(y = str_wrap(income_grp, 15), x = mean_value, fill = income_grp)
) +
geom_density_ridges(show.legend = FALSE, alpha = .7) +
geom_vline(xintercept = 3.07, color = "blue", linetype = "dashed") +
annotate(
geom = "text",
x = 3.5,
y = 6,
hjust = 0,
size = 3,
label = "Global average\n(3.07)",
fontface = "bold",
color = "blue"
) +
scale_x_log10() +
annotation_logticks(sides = "b") +
scale_y_discrete(limits = rev) +
scale_fill_brewer(palette = "Dark2") +
labs(
y = "",
x = "Ratio of excess deaths\nto COVID-19 deaths"
) +
theme_ridges() +
theme(
axis.text.y = element_text(size = 12),
axis.title.x = element_text(size = 10),
panel.grid = element_blank()
)
text_comment <- ggplot() +
annotate(
geom = "text",
label = str_wrap("The difference is more noticable for lower income countries", 20),
hjust = 0,
size = 5,
fontface = "italic",
x = 0,
y = 0
) +
theme_void()
# composed chart
map1 +
inset_element(
inset,
left = 0,
bottom = 0,
right = 0.3,
top = 0.6
) +
inset_element(
text_comment,
left = 0,
bottom = .65,
right = .2,
top = .9
)
ggsave(
filename = "worldwide-distribution-ratio-excess-deaths-to-covid19-deaths.png",
width = 18,
height = 9.5
)
@jmcastagnetto
Copy link
Author

worldwide-distribution-ratio-excess-deaths-to-covid19-deaths

@jmcastagnetto
Copy link
Author

Tried to make the colors distinctive enough to be easy to differentiate for colorblind people. Hope this works.
Perhaps color palettes for the inset ridge plot and the map could be make more compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment