(a) MLE in 1952 for Top 5 and Bottom 5 Countries

Summary and Plot

# Select Data Needed

## Filter, Select, and Arrange Data
life1952 <- gapminder %>% 
  filter(year == 1952) %>% 
  arrange(desc(lifeExp))

## Select Rows
ten1952 <- rbind(top_n(life1952, 5, lifeExp), top_n(life1952, -5, lifeExp))
print(ten1952)
## # A tibble: 10 x 6
##    country      continent  year lifeExp      pop gdpPercap
##    <fct>        <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Norway       Europe     1952    72.7  3327728    10095.
##  2 Iceland      Europe     1952    72.5   147962     7268.
##  3 Netherlands  Europe     1952    72.1 10381988     8942.
##  4 Sweden       Europe     1952    71.9  7124673     8528.
##  5 Denmark      Europe     1952    70.8  4334000     9692.
##  6 Mozambique   Africa     1952    31.3  6446316      469.
##  7 Sierra Leone Africa     1952    30.3  2143249      880.
##  8 Angola       Africa     1952    30.0  4232095     3521.
##  9 Gambia       Africa     1952    30     284320      485.
## 10 Afghanistan  Asia       1952    28.8  8425333      779.
# Plot
ten1952$country <- factor(ten1952$country, levels = ten1952$country)
ggplot(ten1952, aes(x = country, y = lifeExp)) +
  geom_col() +
  labs(title = "Median Life Expectancy in 1952", subtitle = "Top 5 and Bottom 5 Countries", y = "MLE in Years") +
  theme(plot.title = element_text(hjust = 0.5, size = 30, color = "blue"), 
        plot.subtitle = element_text(hjust = 0.5, size = 20, color = "sky blue"),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 8, angle = 30))

Findings

  • There is about 40 years difference between top and bottom countries in MLE.
  • All five highest MLE countries are in Europe, whereas the most of the bottom ones are from Africa.
  • The top countries have higher GDP per capita than bottom countries.
  • The population doesn’t seem to have much correlation with MLE.

(b) MLE in 2007 for Top 5 and Bottom 5 Countries

Summary and Plot

# Select Data Needed

## Filter, Select, and Arrange Data
life2007 <- gapminder %>% 
  filter(year == 2007) %>% 
  arrange(desc(lifeExp))

## Select Rows
ten2007 <- rbind(top_n(life2007, 5, lifeExp), top_n(life2007, -5, lifeExp))
print(ten2007)
## # A tibble: 10 x 6
##    country          continent  year lifeExp       pop gdpPercap
##    <fct>            <fct>     <int>   <dbl>     <int>     <dbl>
##  1 Japan            Asia       2007    82.6 127467972    31656.
##  2 Hong Kong, China Asia       2007    82.2   6980412    39725.
##  3 Iceland          Europe     2007    81.8    301931    36181.
##  4 Switzerland      Europe     2007    81.7   7554661    37506.
##  5 Australia        Oceania    2007    81.2  20434176    34435.
##  6 Lesotho          Africa     2007    42.6   2012649     1569.
##  7 Sierra Leone     Africa     2007    42.6   6144562      863.
##  8 Zambia           Africa     2007    42.4  11746035     1271.
##  9 Mozambique       Africa     2007    42.1  19951656      824.
## 10 Swaziland        Africa     2007    39.6   1133066     4513.
# Plot
ten2007$country <- factor(ten2007$country, levels = ten2007$country)
ggplot(ten2007, aes(x = country, y = lifeExp)) +
  geom_col() +
  labs(title = "Median Life Expectancy in 2007", subtitle = "Top 5 and Bottom 5 Countries", y = "MLE in Years") +
  theme(plot.title = element_text(hjust = 0.5, size = 30, color = "blue"), 
        plot.subtitle = element_text(hjust = 0.5, size = 20, color = "sky blue"),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 8, angle = 30))

Findings

  • There is about 40 years difference between top and bottom countries in MLE.
  • All five lowest MLE countries are in Africa, whereas the top ones are Asia, Europe, and Oceania.
  • The top countries have higher GDP per capita than bottom countries, and this difference is larger than the difference in 1952.
  • The population doesn’t seem to have much correlation with MLE.

(c) MLE in Each Year for Top 5 Countries Based on 2007 Population

Summary and Plot

# Top 5 Countries based on 2007 population
top5Name <- gapminder %>% 
  filter(year == 2007) %>% 
  arrange(desc(pop)) %>% 
  top_n(5, pop)
top5Name$country
## [1] China         India         United States Indonesia     Brazil       
## 142 Levels: Afghanistan Albania Algeria Angola Argentina Australia ... Zimbabwe
# Summary Table
top5 <- gapminder %>% 
  filter(country == top5Name$country[1] |
           country == top5Name$country[2] |
           country == top5Name$country[3] |
           country == top5Name$country[4] |
           country == top5Name$country[5])
top5$country <- factor(top5$country, levels = as.vector(top5Name$country))
datatable(top5)
# Plot
ggplot(top5, aes(x = year, y = lifeExp, color = country)) +
  geom_line() +
  labs(title = "Median Life Expectancy \n for the Largest Five Countries", y = "MLE in Years") +
  theme(plot.title = element_text(hjust = 0.5, size = 20, color = "blue"), 
        axis.title.x = element_blank())

Findings

  • There is an overall increase in MLE for all five countries.
  • United States maintained the highest MLE out of all 5 countries for all years.
  • They all have stable increase in MLE except for China in between 1950 and 1970.
  • None of these countries are one of the five highest MLE countries nor the lowest in 1952 and 2007.
  • The population size does not seem to have much correlation with MLE.

(d) MLE in Each Year for Each Continent

Summary and Plot

Let’s say the median life expectancy of a continent is the median value of MLE in that continent for that specific year.

# Create new column for continent median
continentMLE <- gapminder %>% 
  group_by(continent, year) %>% 
  summarize(contMLE = median(lifeExp, na.rm = TRUE))

datatable(continentMLE)
# Plot
ggplot(continentMLE, aes(x = year, y = contMLE, color = continent)) +
  geom_line() +
  labs(title = "Median Life Expectancy \n for Each Continent", y = "MLE in Years") +
  theme(plot.title = element_text(hjust = 0.5, size = 20, color = "blue"), 
        axis.title.x = element_blank())

Findings

  • There is an overall stable increase in MLE for all continents, and the increased amount is mostly similar across the continents.
  • Oceania maintained the highest MLE in each year, with Europe as the second.
  • Africa always had the lowest MLE.
  • This MLE may not be the true MLE since the median is calculated by the median of countries and the population was not counted as a factor.