── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.3.0
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.1.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)library(rnaturalearth)
Warning: package 'rnaturalearth' was built under R version 4.5.2
library(rnaturalearthdata)
Warning: package 'rnaturalearthdata' was built under R version 4.5.2
Attaching package: 'rnaturalearthdata'
The following object is masked from 'package:rnaturalearth':
countries110
library(plotly)
Warning: package 'plotly' was built under R version 4.5.2
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
library(htmlwidgets)
Warning: package 'htmlwidgets' was built under R version 4.5.2
library(sf)
Warning: package 'sf' was built under R version 4.5.2
Linking to GEOS 3.13.1, GDAL 3.11.4, PROJ 9.7.0; sf_use_s2() is TRUE
# Load cleaned dataload("df_clean.RData")
Question 1: How has the average global infant mortality rate changed over the decades? What is the prevailing trend of infant mortality rate among groups of countries over the last three decades?
p1 <- df_clean |>filter(entity =="World") |>ggplot(aes(x = year, y = rate)) +geom_line(color ="steelblue") +labs(title ="Global Infant Mortality Rate (1990-2023)",x ="Year",y ="Infant deaths per thousand live births",caption ="Source: Our World in Data | Author: Son Pham") +theme_minimal() +theme(plot.title =element_text(face ="bold", size =12, hjust =0.5),axis.title.x =element_text(face ="bold",size =10,margin =margin(t =10)),axis.title.y =element_text(face ="bold",size =10,margin =margin(r =10)),plot.caption =element_text(margin =margin(t =10)),legend.title =element_text(face ="bold",),)ggplotly(p1)
Question 3: What is the infant mortality rate for all countries in the most recent year, and which countries have the highest rates?
df_clean|># Filter dataset to only contain countriesfilter(year ==2023&!is.na(code) & (nchar(code) <4)) |>select(entity, rate, continent) |># Drop geometry column sf::st_drop_geometry(data_all) |>group_by(entity) |>arrange(desc(rate)) |>head(df_merge, n=10)
# A tibble: 10 × 3
# Groups: entity [10]
entity rate continent
<chr> <dbl> <chr>
1 South Sudan 7.26 Africa
2 Somalia 6.78 Africa
3 Niger 6.74 Africa
4 Guinea 6.15 Africa
5 Central African Republic 6.04 Africa
6 Nigeria 6.01 Africa
7 Chad 5.87 Africa
8 Mali 5.76 Africa
9 Sierra Leone 5.62 Africa
10 Lesotho 5.54 Africa
We can see that the top 10 countries with the highest infant mortality rates are from Africa.
# Map of infant mortality rate by country in 2023p4 <- df_clean |>filter(year ==2023&!is.na(code) & (nchar(code) <4)) |>ggplot(aes()) +geom_sf(aes(geometry = geometry, fill = rate)) +scale_fill_gradient(low ="#ffffc5", high ="#ff0000",na.value ="grey90", name ="Infant deaths per 100 births", guide =guide_colorbar(barwidth =10,barheight =0.5,title.position ="top",title.hjust =0.5 )) +labs(title ="Infant Mortality Rate by Country in 2023",fill ="Life Expectancy at Birth",caption ="Source: Our World in Data | By: Son Pham") +theme_void() +theme(plot.title =element_text(face ="bold", size =12, hjust =0.5),legend.position ="bottom",legend.title =element_text(size =10),)p4