Skip to content

Instantly share code, notes, and snippets.

@USMortality
Last active October 25, 2024 00:08
Show Gist options
  • Save USMortality/944c0540f1b7f9a3a3412f3fd0883279 to your computer and use it in GitHub Desktop.
Save USMortality/944c0540f1b7f9a3a3412f3fd0883279 to your computer and use it in GitHub Desktop.
COVID-19 Total Vaccinations per Hundred vs. COVID-19 Cases [World]
library(readr)
library(dplyr)
library(ggrepel)
library(ggpubr)
library(ggpmisc)
library(scales)
library(tidyr)
library(lubridate)
sf <- 2
width <- 1920 * sf
height <- 1080 * sf
options(vsc.dev.args = list(width = width, height = height, res = 72 * sf))
owid <- read_csv("https://covid.ourworldindata.org/data/owid-covid-data.csv")
df <- owid |>
select(
iso_code, continent, date, new_cases_per_million,
people_vaccinated_per_hundred
) |>
arrange(iso_code, date) |>
mutate(
date = year(date),
people_vaccinated_per_hundred = people_vaccinated_per_hundred / 100
) |>
filter(date %in% 2021:2023, !is.na(continent)) |>
group_by(iso_code, continent) |>
fill(people_vaccinated_per_hundred, .direction = "down") |>
replace_na(list(people_vaccinated_per_hundred = 0)) |>
group_by(iso_code, continent, date) |>
summarize(
new_cases_per_million = sum(new_cases_per_million, na.rm = TRUE),
people_vaccinated_per_hundred = max(
people_vaccinated_per_hundred,
na.rm = TRUE
),
.groups = "drop"
)
chart <- ggplot(df, aes(
x = people_vaccinated_per_hundred, y = new_cases_per_million, label = iso_code
)) +
geom_point() +
# geom_text_repel() +
stat_cor(aes(label = paste(..rr.label.., ..p.label.., sep = "~`,`~")),
method = "pearson",
label.x.npc = "left",
label.y.npc = "top",
r.accuracy = 0.01,
p.accuracy = 0.01
) +
stat_poly_line() +
labs(
title = "COVID-19 Total Vaccinations per Hundred vs. COVID-19 Cases",
subtitle = "Source: OWID",
x = "COVID-19 Total Vaccinations per Hundred",
y = "COVID-19 Cases"
) +
theme_bw() +
scale_y_continuous(labels = comma) +
scale_x_continuous(labels = scales::percent_format()) +
facet_wrap(vars(continent, date), scales = "free")
ggplot2::ggsave(
filename = "chart1.png", plot = chart, width = width, height = height,
units = "px", dpi = 72 * sf, device = grDevices::png, type = c("cairo")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment