Task 1: Use world bank data to analyze something

# load the necessary packages
library(wbstats)
library(tidyverse)
library(ggplot2)
library(ggthemes)
theme_set(theme_few())

# Next, I will retrieve the necessary data from the World Bank using the wbstats package. 
# I will be using two indicators: life expectancy at birth (SP.DYN.LE00.IN) and health expenditure 
# per capita (SH.XPD.CHEX.PC.CD).

life_expectancy <- wb_data(indicator = "SP.DYN.LE00.IN", start_date = 1990, end_date = 2019)
health_expenditure <- wb_data(indicator = "SH.XPD.CHEX.PC.CD", start_date = 1990, end_date = 2019)

# To merge the data into one dataframe, I will use the merge_wb function from the wbstats package.
health_life <- merge(health_expenditure, life_expectancy, by = c("iso3c", "date"))


# Now that we have the necessary data, we can explore the relationship between health expenditures 
# and life expectancy over time using a scatter plot.

# Plot life expectancy against health expenditure
ggplot(health_life, aes(x = SH.XPD.CHEX.PC.CD, y = SP.DYN.LE00.IN)) +
  geom_point(alpha = 0.5) +
  scale_x_log10(labels = scales::dollar_format(scale = 1e-9, suffix = "B")) +
  labs(title = "Life Expectancy vs Health Expenditure per capita",
       x = "Health Expenditure per capita (USD)",
       y = "Life Expectancy (years)") +
  theme(plot.title = element_text(hjust = 0.5),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_line(colour = "grey", size = 0.2),
        axis.text = element_text(size = 8))

This graph demonstrates the favorable relationship between health spending per person and life expectancy. The data points are grouped in the plot’s upper left corner, showing that the majority of nations spend less than $10,000 USD per person on health care and have life expectancies under 80 years. However, there are a few anomalies that have a life expectancy of more than 80 years and spend more than 10,000 USD per individual on healthcare.

Conclusion: Although this study demonstrates a correlation between health spending and life expectancy, some nations still have low life expectancies despite high health spending. This emphasizes the requirement for additional study and focused interventions to enhance health results in these nations.