Show me the code
library(tidyverse)
library(readxl)
Life_expectancy_at_birth_Total <- read_excel("C:/Users/vasil/Downloads/Life_expectancy_at_birth_Total.xlsx",
na = "..")Life expectancy at birth is a fundamental measure that reflects the overall health and mortality level of a population. It represents the average number of years a newborn could expect to live if they were to experience the sex- and age-specific death rates prevailing at the time of their birth. In other words, it summarizes the mortality pattern across all age groups, from children and adolescents to adults and the elderly.
Here are the three datasets we will be analyzing:
1. Total life expectancy at birth: This dataset provides the average life expectancy at birth for the entire population, regardless of gender.
library(tidyverse)
library(readxl)
Life_expectancy_at_birth_Total <- read_excel("C:/Users/vasil/Downloads/Life_expectancy_at_birth_Total.xlsx",
na = "..")2. Male life expectancy at birth: Specifically focuses on the average life expectancy at birth for males.
Life_epectancy_at_birth_males <- read_excel("C:/Users/vasil/Downloads/Life_epectancy_at_birth_males.xlsx",
na = "..")3. Female life expectancy at birth: Concentrates on the average life expectancy at birth for females.
Life_expectancy_at_birth_females <- read_excel("C:/Users/vasil/Downloads/Life_expectancy_at_birth_females.xlsx",
na = "..")The first graph illustrates the global trend in total life expectancy at birth from 1960 to 2022. Starting at approximately 51 years in 1960, life expectancy at birth has steadily increased to approximately 72 years by 2022. This upward trajectory highlights significant advancements in healthcare, nutrition, and living conditions over the decades. The consistent rise underscores the ongoing improvements in global health and the effectiveness of public health interventions. This analysis provides a clear picture of how far we’ve come in enhancing the quality of life and longevity worldwide.
library(plotly)
Long_Total_Data<-Life_expectancy_at_birth_Total %>%
pivot_longer(5:68,
names_to = "year",
values_to = "Life_Exp")
ggplotly(Long_Total_Data %>%
separate(col = year,
into = c("year", "[YR]"),
sep = 4) %>%
mutate(year = as.double(year)) %>%
drop_na(year) %>%
filter(`Country Name` == "World") %>%
ggplot() +
geom_point(aes(year, Life_Exp, text = paste("Year:", year,
"<br>Life expectancy:", round(Life_Exp, 2))),
size = 2, colour = "steelblue", alpha = .7) +
geom_line(aes(year, Life_Exp), linewidth = 1, colour = "steelblue") +
scale_x_continuous(breaks = scales::pretty_breaks(n = 5)) +
labs(title = "Total life expectancy at birth (World)",
x = "Year",
y = "Life expectancy (years)") +
theme_minimal() +
theme(plot.title =
element_text(size = 18,
face = "bold",
colour = "steelblue",
hjust = 0.5),
axis.text =
element_text(size = 10,
colour = "grey",
face = "bold"),
axis.title =
element_text(size = 12,
colour = "steelblue")),
tooltip = "text") %>%
layout(legend = list(x = 0.8, y = 0),
margin = list(b = 100),
annotations = list( x = 0.05,
y = -0.1,
text = "Source: World Bank",
showarrow = FALSE,
xref = 'paper',
yref = 'paper',
xanchor = 'center',
yanchor = 'top',
font = list(size = 12, color = "grey")),
hovermode = "closest",
hoverlabel = list(bgcolor = "steelblue", font = list(size = 12)))The second graph delves into the life expectancy at birth for males and females from 1960 to 2022. This analysis reveals distinct trends and highlights the differences in longevity between genders over the decades.
library(plotly)
Long_Male_Data <- Life_epectancy_at_birth_males %>%
pivot_longer(5:68,
names_to = "year",
values_to = "Life_Exp")
Long_Female_Data <- Life_expectancy_at_birth_females %>%
pivot_longer(5:68,
names_to = "year",
values_to = "Life_Exp")
gender_data <- rbind(Long_Male_Data, Long_Female_Data)
ggplotly(gender_data %>%
separate(col = "year",
into = c("year", "[YR]"),
sep = 4) %>%
mutate(year = as.double(year)) %>%
drop_na(year) %>%
filter(`Country Name` == "World") %>%
ggplot() +
geom_line(aes(year, Life_Exp, colour = `Series Name`), linewidth = 1) +
geom_point(aes(year, Life_Exp, text = paste("Year:", year,
"<br>Life expectancy:", round(Life_Exp, 2)),
colour = `Series Name`), size = 2, alpha = .7) +
scale_color_manual(values = c("Life expectancy at birth, male (years)" = "steelblue",
"Life expectancy at birth, female (years)" = "#ca47a9"),
labels = c("Life expectancy at birth, male (years)" = "Life expectancy at birth, male",
"Life expectancy at birth, female (years)" = "Life expectancy at birth, female")) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 5)) +
labs(title = "Life expectancy at birth by gender",
x = "Year",
y = "Life expectancy (years)") +
theme_minimal() +
theme(plot.title =
element_text(size = 18,
face = "bold",
color = "steelblue",
hjust = .5),
axis.text =
element_text(size = 10,
colour = "grey",
face = "bold"),
axis.title =
element_text(size = 12,
colour = "steelblue"))+
guides(colour =guide_legend(title = NULL)),
tooltip = "text") %>%
layout(legend = list(x = 0.7, y = -0.12),
margin = list(b = 100),
annotations = list(
x = 0.04,
y = -0.1,
text = "Source: World Bank",
showarrow = FALSE,
xref = 'paper',
yref = 'paper',
xanchor = 'center',
yanchor = 'top',
font = list(size = 12, color = "grey")),
hovermode = "closest",
hoverlabel = list(font = list(size = 12)))In 1960, the average life expectancy at birth for females was approximately 53 years. Over the next six decades, this figure has shown a consistent upward trend, reaching around 74.5 years by 2022. This significant increase of over 21 years underscores the remarkable advancements in healthcare, nutrition, and overall living conditions that have particularly benefited women. Factors such as improved maternal health services, better access to education, and increased health awareness have played crucial roles in enhancing female life expectancy.
For males, the journey began at a slightly lower average life expectancy at birth of approximately 49 years in 1960. By 2022, this figure had risen to about 69.5 years, marking an increase of over 20 years. While the upward trend is similar to that of females, the gap between male and female life expectancy has persisted. Gender disparities in life expectancy can be influenced by a variety of factors, such as biological and behavioral.
This analysis investigates possible correlations and patterns between life expectancy at birth and economic groups, in an effort to measure the influence of wealth and resources on health outcomes.
invisible(Long_Total_Data %>%
filter(grepl("income", `Country Name`, ignore.case = TRUE)) %>%
distinct(`Country Name`))
ggplotly(Long_Total_Data %>%
separate(col = "year",
into = c("year", "[YR]"),
sep = 4) %>%
mutate(year = as.double(year)) %>%
drop_na(year) %>%
filter(`Country Name` %in% c("High income",
"Upper middle income",
"Middle income",
"Lower middle income",
"Low income")) %>%
mutate(`Country Name` = factor(`Country Name`,
levels = c("High income",
"Upper middle income",
"Middle income",
"Lower middle income",
"Low income"))) %>%
ggplot() +
geom_line(aes(year, Life_Exp, colour = `Country Name`), linewidth = .5) +
geom_point(aes(year, Life_Exp, text = paste("Year:", year,
"<br>Life expectancy:", round(Life_Exp, 2)),
colour = `Country Name`), size = 1, alpha = .7) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 5)) +
labs(title = "Life expectancy at birth by economic group",
x = "Year",
y = "Life expectancy (years)")+
theme_minimal() %>%
theme(plot.title =
element_text(size = 18,
face = "bold",
colour = "steelblue",
hjust = .5),
axis.text =
element_text(size = 10,
colour = "grey",
face = "bold"),
axis.title =
element_text(size = 12,
colour = "steelblue"),
panel.background = element_rect(fill = "white", colour = NA),
panel.grid.major = element_line(color = scales::alpha("grey", 0.2), linewidth = 0.5),
legend.text = element_text(size = 8),
legend.key.size = unit(0.5, "cm")) +
guides(colour = guide_legend(title = "Economic group")),
tooltip = "text") %>%
layout(legend = list(x = .8, y = 0.02, traceorder = "normal",
font = list(size = 10),
itemclick = "toggleothers",
itemdoubleclick = "toggle"),
margin = list(b = 100),
annotations = list(
x = 0.02,
y = -0.1,
text = "Source: World Bank",
showarrow = FALSE,
xref = 'paper',
yref = 'paper',
xanchor = 'center',
yanchor = 'top',
font = list(size = 12, color = "grey")))High-income countries started with a life expectancy of approximately 68.5 years in 1960, climbing to around 80 years by 2022. This significant increase of over 11 years indicates that high-income countries have benefited most from advancements in healthcare, nutrition, and living standards. The stability and gradual rise in life expectancy in these countries underscores the impact of sustained investment in health infrastructure and technology, as well as comprehensive healthcare policies.
For upper middle-income countries, life expectancy at birth increased from about 43.5 years in 1960 to approximately 75.5 years by 2022. This dramatic rise of 32 years reflects rapid improvements in health services, economic growth, and educational access. The transformation in these countries can be attributed to large-scale public health initiatives, vaccination programs, and socioeconomic policies that have reduced poverty and improved living conditions significantly.
Middle-income countries saw their life expectancy rise from around 45 years in 1960 to approximately 71 years by 2022. This increase of 26 years demonstrates substantial progress in public health measures, albeit not as pronounced as in upper middle-income countries. These countries have seen varied progress due to different rates of economic development and healthcare investments, highlighting the importance of targeted health interventions and sustainable economic policies.
Life expectancy in lower middle-income countries improved from approximately 47 years in 1960 to about 67.5 years by 2022, an increase of around 20.5 years. While progress has been made, the slower rate of improvement compared to higher-income groups emphasizes ongoing challenges such as limited access to quality healthcare, poor living conditions, and economic instability. Targeted initiatives focusing on maternal and child health, infectious disease control, and education are essential for further advancements.
Starting at a life expectancy of approximately 41 years in 1960 and rising to about 63 years by 2022, low-income countries experienced an increase of 22 years. Despite this growth, these countries remain at the lower end of the spectrum, reflecting persistent hurdles such as underfunded health systems, high disease burden, and socioeconomic constraints. Addressing these issues requires global cooperation, significant financial investment, and innovative health solutions to bridge the gap.
In summary, our analysis reveals substantial improvements in global life expectancy at birth from 1960 to 2022. However, significant disparities persist between different economic groups, highlighting the influence of socioeconomic factors on health outcomes. High-income countries have seen the greatest gains, while low-income countries continue to face considerable challenges. Addressing these disparities requires targeted public health interventions, economic policies, and global cooperation.
The analysis of life expectancy by gender shows that females generally have a higher life expectancy at birth than males. From 1960 to 2022, female life expectancy at birth increased from approximately 53 years to around 74.5 years, while male life expectancy rose from about 49 years to 69.5 years. Factors that influence gender differences in mortality include biological factors, such as hormonal influences on physiology and behavior, and environmental factors, such as cultural influences on gender differences in health behaviors. There is a need for evidence-based findings to develop and refine health policies and interventions that effectively address gender-specific health needs.
1. World Bank. Total life expectancy at birth dataset. Retrieved from https://data.worldbank.org/indicator/SP.DYN.LE00.IN
2. World Bank. Life expectancy at birth, male (years) dataset. Retrieved from https://data.worldbank.org/indicator/SP.DYN.LE00.MA.IN
3. World Bank. Life expectancy at birth, female (years) dataset. Retrieved from https://data.worldbank.org/indicator/SP.DYN.LE00.FE.IN