The objective is to analyze and visualize global economic and social indicators, including life expectancy, GDP per capita, and population, across different countries and years. The findings will reveal disparities, trends, and patterns in global development.
library(gapminder)
## Warning: package 'gapminder' was built under R version 4.4.2
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.2
##
## 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(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.2
data("gapminder")
# Data Preprocessing
gapminder_filtered <- gapminder %>%
select(country, year, lifeExp, gdpPercap, pop, continent) %>%
filter(year >= 2000) %>% # Focus on data from the year 2000 onwards
mutate(gdp_billion = gdpPercap * pop / 1e9) # Calculate GDP in billion dollars
# Summary Table by Continent
summary_table <- gapminder_filtered %>%
group_by(continent) %>%
summarise(
avg_lifeExp = mean(lifeExp, na.rm = TRUE),
avg_gdpPercap = mean(gdpPercap, na.rm = TRUE),
total_pop = sum(pop, na.rm = TRUE)
) %>%
arrange(desc(total_pop))
# Display the top rows
head(summary_table)
## # A tibble: 5 Ă— 4
## continent avg_lifeExp avg_gdpPercap total_pop
## <fct> <dbl> <dbl> <dbl>
## 1 Asia 70.0 11324. 7413756030
## 2 Africa 54.1 2844. 1763263608
## 3 Americas 73.0 10145. 1748643946
## 4 Europe 77.2 23383. 1164322398
## 5 Oceania 80.2 28374. 48004776
# Life Expectancy Trend Over Time (2000 onwards)
ggplot(gapminder_filtered, aes(x = year, y = lifeExp, color = continent, group = continent)) +
geom_line() +
labs(
title = "Life Expectancy Trend Over Time (2000 onwards)",
x = "Year",
y = "Life Expectancy"
) +
scale_color_manual(values = c("Asia" = "#FF6347", "Europe" = "#4682B4", "Africa" = "#32CD32", "Americas" = "#FFD700", "Oceania" = "#8A2BE2")) + # Custom colors
theme_minimal()
# GDP per Capita Distribution by Continent
ggplot(gapminder_filtered, aes(x = gdpPercap, fill = continent)) +
geom_density(alpha = 0.7) +
scale_x_log10() + # Log scale for GDP per capita
labs(
title = "GDP per Capita Distribution by Continent",
x = "GDP per Capita (log scale)",
y = "Density"
) +
scale_fill_manual(values = c("Asia" = "#FF6347", "Europe" = "#4682B4", "Africa" = "#32CD32", "Americas" = "#FFD700", "Oceania" = "#8A2BE2")) + # Custom colors
theme_minimal()
# Life Expectancy Distribution by Continent
ggplot(gapminder_filtered, aes(x = continent, y = lifeExp, fill = continent)) +
geom_boxplot() +
labs(
title = "Life Expectancy Distribution by Continent",
x = "Continent",
y = "Life Expectancy"
) +
scale_fill_manual(values = c("Asia" = "#FF6347", "Europe" = "#4682B4", "Africa" = "#32CD32", "Americas" = "#FFD700", "Oceania" = "#8A2BE2")) + # Custom colors
theme_minimal()
options(timeout = 600) # Increase the timeout limit (in seconds)
Life Expectancy Trends: Over time, life expectancy
has generally risen across the globe, with notable progress observed in
Asia and Latin America. However, significant disparities remain between
continents.
GDP Distribution: The density plot highlights a skewed
distribution of GDP per capita, where a large portion of the world’s
population resides in lower-income regions, particularly in Africa and
Asia.
Regional Variability: The box plot indicates that
Africa has a broader range of life expectancy values, reflecting
substantial disparities within the continent. In contrast, Europe
displays a narrower range, signifying more consistent health outcomes
across the region.
This analysis sheds light on the economic and social disparities observed across continents. The visualizations underscore key trends, such as the global increase in life expectancy, the concentration of wealth in certain regions, and the differences in health outcomes. Further investigation is required to understand the policies that have influenced these trends and explore how countries can share knowledge and experiences to address these disparities effectively.