The objective of this analysis is to explore global economic and health trends using the Gapminder dataset from the year 2000 onwards. Specifically, the study aims to analyze GDP per capita across various countries to identify the wealthiest nations and understand the distribution of wealth worldwide. It also investigates the relationship between GDP per capita and life expectancy, assessing whether wealthier countries tend to have better health outcomes. Furthermore, the analysis tracks the evolution of GDP per capita over time for selected countries to observe economic growth patterns across developing and developed nations. Additionally, an interactive map is used to visualize these trends geographically, showcasing differences in GDP per capita and life expectancy across regions. Through this approach, the study provides insights into how economic prosperity correlates with health outcomes and how these variables have changed in recent decades.
knitr::opts_chunk$set(echo = TRUE)
# Load Required Libraries
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(leaflet)
library(gapminder)
# Load the Data
data("gapminder") # Load Gapminder dataset
gapminder_data <- gapminder # Assign dataset to a variable for easier reference
# Inspect the Data
glimpse(gapminder_data) # View the structure of the dataset
## 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, …
# Data Wrangling
# Select relevant columns: gdpPercap (GDP per capita), lifeExp (life expectancy), and pop (population)
processed_data <- gapminder_data %>%
filter(year >= 2000) %>% # Filter for data from 2000 onwards
mutate(gdp_per_capita = gdpPercap, # Rename 'gdpPercap' for consistency
life_expectancy = lifeExp, # Rename 'lifeExp'
population = pop) # Use population as is
# Table Output: Summarize GDP per capita trends by country
gdp_summary <- processed_data %>%
group_by(country) %>%
summarize(
avg_gdp_per_capita = mean(gdp_per_capita, na.rm = TRUE),
avg_life_expectancy = mean(life_expectancy, na.rm = TRUE),
avg_population = mean(population, na.rm = TRUE)
) %>%
arrange(desc(avg_gdp_per_capita)) %>%
head(10) # Top 10 countries by average GDP per capita
print(gdp_summary)
## # A tibble: 10 × 4
## country avg_gdp_per_capita avg_life_expectancy avg_population
## <fct> <dbl> <dbl> <dbl>
## 1 Norway 47021. 79.6 4581758.
## 2 Singapore 41583. 79.4 4375392.
## 3 Kuwait 41209. 77.2 2308560
## 4 United States 41024. 77.8 294407736.
## 5 Ireland 37377. 78.3 3994120.
## 6 Switzerland 35994. 81.2 7458209
## 7 Netherlands 35261. 79.1 16346722.
## 8 Hong Kong, China 34967. 81.9 6871444
## 9 Canada 34824. 80.2 32646204.
## 10 Austria 34272. 79.4 8174048.
# Visualization 1: Density Plot of GDP per Capita
# Shows the distribution of GDP per capita across countries from 2000 onwards
ggplot(processed_data, aes(x = gdp_per_capita)) +
geom_density(fill = "skyblue", alpha = 0.6) +
labs(
title = "Density Plot of GDP per Capita (2000 onwards)",
x = "GDP Per Capita", y = "Density"
) +
theme_minimal()
# Visualization 2: Scatter Plot of GDP per Capita vs Life Expectancy
# Size of points represents the population of the country
ggplot(processed_data, aes(x = gdp_per_capita, y = life_expectancy, size = population, color = continent)) +
geom_point(alpha = 0.6) +
scale_size_continuous(range = c(1, 12), guide = "none") + # Adjust the range for better visualization
labs(
title = "Relationship between GDP per Capita and Life Expectancy",
x = "GDP Per Capita", y = "Life Expectancy"
) +
theme_minimal()
# Visualization 3: Faceted Line Plot of GDP Per Capita Over Time
# For a selection of countries
selected_countries <- c("Norway", "United States", "China", "India", "Brazil", "Germany", "Australia")
gapminder_selected <- processed_data %>%
filter(country %in% selected_countries)
ggplot(gapminder_selected, aes(x = year, y = gdp_per_capita, color = country)) +
geom_line(size = 1.2) +
facet_wrap(~ country, scales = "free_y") +
labs(
title = "GDP per Capita Over Time (2000 onwards)",
x = "Year", y = "GDP Per Capita (USD)"
) +
theme_minimal() +
theme(legend.position = "none")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Data Cleaning for Map Visualization
# Filter out rows with missing values in relevant columns before plotting
processed_data_clean <- processed_data %>%
filter(!is.na(gdp_per_capita) & !is.na(life_expectancy))
# Preparing data for Leaflet
# Sample coordinates for a few countries (you can extend this list)
country_coords <- data.frame(
country = c("Norway", "United States", "China", "India", "Germany", "Australia", "Brazil"),
latitude = c(60.4720, 37.0902, 35.8617, 20.5937, 51.1657, -25.2744, -14.2350),
longitude = c(8.4689, -95.7129, 104.1954, 78.9629, 10.4515, 133.7751, -51.9253)
)
# Merge processed
This analysis investigates global economic and health trends from 2000 onwards using the Gapminder dataset. By focusing on GDP per capita and life expectancy, the study reveals key insights into the wealth and health outcomes of various countries. The data shows significant income inequality, with a few countries standing out as having extremely high GDP per capita. A positive correlation between GDP per capita and life expectancy suggests that wealthier countries tend to have better health outcomes, but this relationship is not perfectly linear. Additionally, tracking GDP per capita over time highlights the rapid economic growth of developing nations, especially in Asia. An interactive map further visualizes these disparities, revealing that countries in Europe and North America generally exhibit higher GDP per capita and life expectancy, while countries in Africa and parts of Asia tend to lag behind.
The analysis highlights the stark income inequality that exists globally, with wealth concentrated in a few countries. While wealthier nations tend to experience better health outcomes, as indicated by longer life expectancy, some countries achieve high life expectancy despite lower GDP, demonstrating that economic wealth is not the only factor influencing public health. The rapid growth in GDP per capita in developing countries like China and India reflects the shifting dynamics of global economic power. However, the relatively lower life expectancy in these nations underscores the complexity of health outcomes, which depend on multiple factors beyond economic growth. The geographic disparities visualized through the interactive map reinforce the need for policies that address both economic and health challenges, particularly in less-developed regions. The findings suggest that economic development alone is insufficient to guarantee improved health outcomes, highlighting the importance of investing in healthcare and social infrastructure.