🌍 1. Business Question

This analysis explores how economic development relates to life expectancy across countries and over time. The goal is to understand whether higher GDP is associated with longer life expectancy and how this relationship evolves globally.


📊 2. Dataset Overview

glimpse(gapminder)
## Rows: 1,704
## Columns: 6
## $ country   <fct> "Afghanistan", "Afghanistan", "Afghanistan", "Afghanistan", …
## $ continent <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, …
## $ year      <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997, …
## $ lifeExp   <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.8…
## $ pop       <int> 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 12…
## $ gdpPercap <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134, …
summary(gapminder)
##         country        continent        year         lifeExp     
##  Afghanistan:  12   Africa  :624   Min.   :1952   Min.   :23.60  
##  Albania    :  12   Americas:300   1st Qu.:1966   1st Qu.:48.20  
##  Algeria    :  12   Asia    :396   Median :1980   Median :60.71  
##  Angola     :  12   Europe  :360   Mean   :1980   Mean   :59.47  
##  Argentina  :  12   Oceania : 24   3rd Qu.:1993   3rd Qu.:70.85  
##  Australia  :  12                  Max.   :2007   Max.   :82.60  
##  (Other)    :1632                                                
##       pop              gdpPercap       
##  Min.   :6.001e+04   Min.   :   241.2  
##  1st Qu.:2.794e+06   1st Qu.:  1202.1  
##  Median :7.024e+06   Median :  3531.8  
##  Mean   :2.960e+07   Mean   :  7215.3  
##  3rd Qu.:1.959e+07   3rd Qu.:  9325.5  
##  Max.   :1.319e+09   Max.   :113523.1  
## 

We focus on key indicators: - GDP per capita - Life expectancy - Population - Year - Country & continent


📈 3. Global Life Expectancy Over Time

gapminder %>%
  group_by(year) %>%
  summarize(avg_lifeExp = mean(lifeExp)) %>%
  ggplot(aes(x = year, y = avg_lifeExp)) +
  geom_line(color = "steelblue", linewidth = 1.2) +
  geom_point() +
  labs(
    title = "Global Average Life Expectancy Over Time",
    x = "Year",
    y = "Life Expectancy (Years)"
  ) +
  theme_minimal()


🌎 4. Life Expectancy by Continent

ggplot(gapminder, aes(x = continent, y = lifeExp, fill = continent)) +
  geom_boxplot(alpha = 0.8) +
  labs(
    title = "Life Expectancy Distribution by Continent",
    x = "Continent",
    y = "Life Expectancy (Years)"
  ) +
  theme_minimal() +
  theme(legend.position = "none")


💰 5. GDP vs Life Expectancy (Core Relationship)

ggplot(gapminder, aes(x = gdpPercap, y = lifeExp)) +
  geom_point(aes(color = continent), alpha = 0.6) +
  scale_x_log10() +
  geom_smooth(method = "loess", se = FALSE, color = "black") +
  labs(
    title = "GDP per Capita vs Life Expectancy",
    x = "GDP per Capita (log scale)",
    y = "Life Expectancy",
    color = "Continent"
  ) +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'


🧭 6. Country-Level Growth Example

We track selected countries over time.

focus_countries <- c("United States", "China", "India", "Brazil")

gapminder %>%
  filter(country %in% focus_countries) %>%
  ggplot(aes(x = year, y = lifeExp, color = country)) +
  geom_line(linewidth = 1.2) +
  geom_point() +
  labs(
    title = "Life Expectancy Trends in Major Countries",
    x = "Year",
    y = "Life Expectancy",
    color = "Country"
  ) +
  theme_minimal()


📦 7. Population vs GDP Relationship

ggplot(gapminder, aes(x = gdpPercap, y = pop)) +
  geom_point(aes(color = continent), alpha = 0.4) +
  scale_x_log10() +
  scale_y_log10() +
  labs(
    title = "Population vs GDP per Capita",
    x = "GDP per Capita (log scale)",
    y = "Population (log scale)",
    color = "Continent"
  ) +
  theme_minimal()


🧠 8. Key Insights