1 Packages

library(ggplot2)
library(lubridate)
library(readxl)
library(gridExtra)
library(ggpubr)
library(naniar)
library(tidyr)
library(dplyr)
library(ggrepel)

2 Basics of plotting with ggplot2

2.1 Figure 2.3 (2019): Hip replacement mean change with 95% CI

2.1.1 Load data

fig23 <- read_excel("Week 4.xlsx", sheet = "Fig2.32019")
head(fig23)
## # A tibble: 6 × 5
##   AVERAGE            Period  Mean Confidence_interval     SE
##   <chr>              <chr>  <dbl>               <dbl>  <dbl>
## 1 Australia - ACORN* 6-mo   0.29              0.0153  0.0047
## 2 England*           6-mo   0.268             0.00223 0     
## 3 Canada - Alberta   12-mo  0.260             0.0185  0.01  
## 4 Netherlands        12-mo  0.263             0.00603 0     
## 5 Sweden             12-mo  0.195             0.00642 0     
## 6 Canada - Manitoba~ 12-mo  0.205             0.0170  0

2.1.2 Scatter plot

ggplot(fig23, aes(x = AVERAGE, y = Mean)) +
  geom_point() +
  labs(x = "Country", y = "Mean") +
  ggtitle("Hip replacement mean, by country")

2.1.3 Bar plot

ggplot(fig23, aes(x = AVERAGE, y = Mean)) +
  geom_bar(stat = "identity") +
  labs(x = "Country", y = "Mean") +
  ggtitle("Hip replacement mean by country") +
  theme_minimal()

2.1.4 Bar plot + error bars

ggplot(fig23, aes(x = AVERAGE, y = Mean)) +
  geom_bar(stat = "identity") +
  geom_errorbar(
    aes(ymin = Mean - Confidence_interval, ymax = Mean + Confidence_interval),
    width = 0.1
  ) +
  labs(x = "Country", y = "Mean") +
  ggtitle(
    "Hip replacement: adjusted mean change between pre- and post-operative EQ-5D-3L scores (US valuation), with 95% confidence intervals"
  ) +
  theme_minimal()


3 Figure 2.5: Vaccination progress & weekly new COVID-19 cases

fig25 <- read_excel("Week 4.xlsx", sheet = "Fig2.5")

fig25subset <- subset(
  fig25,
  country %in% c("Israel", "United States Of America", "United Kingdom")
)

fig25subset <- subset(fig25subset, indicator == "cases")

fig25subset <- separate(fig25subset, col = year_week, into = c("Year", "Week"), sep = "-")

fig25subset$Year <- as.numeric(fig25subset$Year)
fig25subset$Week <- as.numeric(fig25subset$Week)

fig25subset$Weeknew <- ifelse(
  fig25subset$Year == 2021, fig25subset$Week + 52,
  ifelse(fig25subset$Year == 2022, fig25subset$Week + 104, fig25subset$Week)
)
ggplot(fig25subset, aes(x = Weeknew, y = weekly_count, fill = Year, color = Year)) +
  geom_point() +
  facet_wrap(~country) +
  geom_line()


4 Figure 2.16: Breast cancer screening proportions

fig216 <- read_excel("Week 4.xlsx", sheet = "Fig2.16")

fig216 <- fig216 %>%
  mutate(`2019` = ifelse(`2019` == "..", NA, `2019`))

fig216$`2019` <- as.numeric(fig216$`2019`)

long_fig216 <- fig216 %>% gather(Year, Proportion, "2018":"2019")

ggplot(long_fig216, aes(x = Country, y = Proportion, fill = Year)) +
  geom_bar(stat = "identity", position = position_dodge(), na.rm = TRUE) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))


5 Figure 3.19: Prevalence of anxiety

fig319 <- read_excel("Week 4.xlsx", sheet = "Fig3.19")

fig319$year2020 <- fig319$`2020`
fig319$year2021 <- fig319$`2021`
fig319$precovid <- fig319$`Pre-COVID-19`

long_fig319 <- fig319 %>% gather(Type, Prevalence, year2020:precovid)

ggplot(long_fig319, aes(x = Country, y = Prevalence, fill = Type)) +
  geom_bar(stat = "identity", position = "dodge") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))


6 Figure 3.9: Main causes of avoidable mortality

fig39 <- read_excel("Week 4.xlsx", sheet = "Fig3.9")

ggplot(fig39, aes(x = "", y = Percentage, fill = Causes)) +
  geom_bar(stat = "identity", width = 1, color = "white", na.rm = TRUE) +
  coord_polar("y", start = 0) +
  theme_void()


7 Figure 5.9: Composition of out-of-pocket spending

fig59 <- read_excel("Week 4.xlsx", sheet = "Fig5.9")

long_fig59 <- fig59 %>% gather(Type, OOP, "Medical Goods":"Other")

ggplot(long_fig59, aes(fill = Type, y = OOP, x = Country)) +
  geom_bar(position = "fill", stat = "identity") +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1))


8 Figure 8.1: Employment in health & social work

fig81 <- read_excel("Week 4.xlsx", sheet = "Fig8.1")

long_fig81 <- fig81 %>% gather(key = "Year", value = "Employ", "2000":"2019")

long_fig81 <- long_fig81 %>%
  mutate(
    paired = rep(1:(n() / 2), each = 2),
    year = factor(Year)
  )

ggplot(long_fig81, aes(x = Country, y = Employ, group = Year, color = Year)) +
  geom_point() +
  geom_line(aes(group = paired)) +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) +
  labs(x = "Countries", y = "% of Health Employment")


9 Figure 1.7: Life expectancy vs health expenditure

LifeExp <- read_excel("Week 4.xlsx", sheet = "LifeExp")
SpendGDP <- read_excel("Week 4.xlsx", sheet = "SpendGDP")

fig17 <- merge(x = LifeExp, y = SpendGDP, by = "Country")

fig17$Life_Exp2017 <- fig17$`2017`
fig17$GDP_Health <- fig17$Total

ggplot(fig17, aes(Life_Exp2017, GDP_Health)) +
  labs(x = "Life Expectancy (2017)", y = "% of GDP Spent in Health") +
  ggtitle("Life expectancy and Health expenditure") +
  geom_hline(yintercept = 10, color = "lightgrey", size = 1.5) +
  geom_vline(xintercept = 75, color = "lightgrey", size = 1.5) +
  geom_point() +
  geom_text_repel(aes(label = Country)) +
  geom_smooth(method = lm)