A. Summarize and plot the median life expectancy (MLE) in 1952 for each of the 5 countries with the top MLE’s and for each of the 5 countries with the bottom MLE’s. You should have one summary table and one plot.
filter1952 <- gapminder %>% filter(year==1952) %>% arrange(lifeExp)
Comb1952 <- rbind(head(filter1952,5),tail(filter1952,5))
LE1952 <- Comb1952 %>% select("Country" = country, "Life Expectancy" = lifeExp)
formattable(LE1952, align = "l")
| Country | Life Expectancy |
|---|---|
| Afghanistan | 28.801 |
| Gambia | 30.000 |
| Angola | 30.015 |
| Sierra Leone | 30.331 |
| Mozambique | 31.286 |
| Denmark | 70.780 |
| Sweden | 71.860 |
| Netherlands | 72.130 |
| Iceland | 72.490 |
| Norway | 72.670 |
ggplot(LE1952, aes(x= reorder(Country, `Life Expectancy`), y=`Life Expectancy`)) +
geom_col(fill='steelblue') +
theme(axis.text.x =element_text(angle=45, hjust=1), plot.title = element_text(hjust = 0.5), plot.subtitle=element_text(hjust = 0.5)) +
labs(title="Lowest and Highest Life Expectancies (MLE)", subtitle="in 1952", x="Country", y="Life Expectancy")
Comparing the highest and lowest median life expectancies (MLE) in 1952 reveals that the top five countries have MLEs which are over twice as high as the lowest five countries with a gap of about 40 years. Four of the five countries with the lowest MLEs are African countries, with the exception of Afghanistan, a South-Asian country. Conversely, all of the top five countries are European, with four of them being Scandinavian countries. The disparity between the highest and lowest countries can likely be attributed to their level of military, political, and economic stability, or lack thereof. It is possible, however, that people who make it to adulthood live longer than the data might suggest for the lowest five countries, as the data could be affected by infant mortality and deaths due to military conflict.
B. Summarize and plot the median life expectancy (MLE) in 2007 for each of the 5 countries with the top MLE’s and for each of the 5 countries with the bottom MLE’s. You should have one summary table and one plot.
filter2007 <- gapminder %>% filter(year==2007) %>% arrange(lifeExp)
Comb2007 <- rbind(head(filter2007,5),tail(filter2007,5))
LE2007 = Comb2007 %>% select("Country" = country, "Life Expectancy" = lifeExp)
formattable(LE2007, align = "l")
| Country | Life Expectancy |
|---|---|
| Swaziland | 39.613 |
| Mozambique | 42.082 |
| Zambia | 42.384 |
| Sierra Leone | 42.568 |
| Lesotho | 42.592 |
| Australia | 81.235 |
| Switzerland | 81.701 |
| Iceland | 81.757 |
| Hong Kong, China | 82.208 |
| Japan | 82.603 |
ggplot(LE2007, aes(x= reorder(Country, `Life Expectancy`), y=`Life Expectancy`)) +
geom_col(fill='steelblue') +
theme(axis.text.x =element_text(angle=45, hjust=1), plot.title = element_text(hjust = 0.5), plot.subtitle=element_text(hjust = 0.5)) +
labs(title="Lowest and Highest Life Expectancies (MLE)", subtitle="in 2007", x="Country", y="Life Expectancy")
As of 2007, all five countries with the lowest MLE are African countries, with most of them being South-African countries. These life expectancies are not likely to be much affected by conflict, but rather due to low availability of resources, as there have not been recent large scale or organized conflicts in the region. The top five highest countries have become more diverse in recent history, with 2 European countries, 2 Asian countries, and Australia enjoying the highest MLEs. These countries all have easy access to life-improving and life-saving resources, such as food, clean water, shelter, and access to health care. Comparing trends, it appears the gap between the highest and lowest countries has remained stable with about 40 years between them; however, the MLE of both the bottom five and top five countries has increased by about 10 years.
C. Summarize and plot the median life expectancy in each year for the largest 5 countries in terms of 2007 population. You should have one summary table and one plot.
Top5pop <- gapminder %>% filter(year==2007) %>% arrange(-pop) %>% head(5) %>% .$country %>% as.vector()
Top5popMLE <- gapminder %>% filter(country %in% Top5pop)
T5PMLE <- Top5popMLE %>% select("Country" = country, "Life Expectancy" = lifeExp, "Year" = year)
PivotT5 = T5PMLE %>% pivot_wider(names_from = Year, values_from = `Life Expectancy`)
formattable(PivotT5, align="l", list(area(col = 2:13) ~ color_tile("#fc4e4e", "#fff2f2")))
| Country | 1952 | 1957 | 1962 | 1967 | 1972 | 1977 | 1982 | 1987 | 1992 | 1997 | 2002 | 2007 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Brazil | 50.91700 | 53.28500 | 55.66500 | 57.63200 | 59.50400 | 61.48900 | 63.33600 | 65.20500 | 67.05700 | 69.38800 | 71.00600 | 72.39000 |
| China | 44.00000 | 50.54896 | 44.50136 | 58.38112 | 63.11888 | 63.96736 | 65.52500 | 67.27400 | 68.69000 | 70.42600 | 72.02800 | 72.96100 |
| India | 37.37300 | 40.24900 | 43.60500 | 47.19300 | 50.65100 | 54.20800 | 56.59600 | 58.55300 | 60.22300 | 61.76500 | 62.87900 | 64.69800 |
| Indonesia | 37.46800 | 39.91800 | 42.51800 | 45.96400 | 49.20300 | 52.70200 | 56.15900 | 60.13700 | 62.68100 | 66.04100 | 68.58800 | 70.65000 |
| United States | 68.44000 | 69.49000 | 70.21000 | 70.76000 | 71.34000 | 73.38000 | 74.65000 | 75.02000 | 76.09000 | 76.81000 | 77.31000 | 78.24200 |
ggplot(T5PMLE, aes(x=Year, y=`Life Expectancy`, color=Country)) + geom_line() +
theme(axis.text.x =element_text(angle=45, hjust=1), plot.title = element_text(hjust = 0.5), plot.subtitle=element_text(hjust = 0.5)) +
labs(title="Life Expectancies of Top 5 Most Populous Countries Since 1952*", caption="*Population as of 2007", x="Country", y="Life Expectancy")
The most populous countries as of 2007 are China, India, United States, Indonesia, and Brazil. All five countries have increased their life expectancies since 1952. Four have steadily increased, while China had a notable decrease in life expectancy between 1957 and 1962. This drop can almost certainly be attributed to the “Great Chinese Famine”, a three year period of famine between 1959 and 1961 as a result of agricultural changes and droughts. However, as of 2007, China has caught up and has the 2nd highest life expectancy out of the five most populous countries. The United States has continuously had the highest MLE of the countries in this group and has slowly increased since 1952. Indonesia has seen the biggest increase in MLE with an increase of roughly 33 years, almost doubling their life expectancy.
D. Summarize and plot the median life expectancy in each year for each continent. You should have one summary table and one plot.
ContinentMLE = gapminder %>% group_by(continent, year) %>% mutate(lifeExp = sum(lifeExp)/n()) %>% subset(select = c(continent, lifeExp, year)) %>% unique()
PivotContinent = ContinentMLE %>% pivot_wider(names_from = year, values_from = lifeExp)
formattable(PivotContinent, align="l", list(area(col = 2:13) ~ color_tile("#fc4e4e", "#fff2f2")))
| continent | 1952 | 1957 | 1962 | 1967 | 1972 | 1977 | 1982 | 1987 | 1992 | 1997 | 2002 | 2007 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Asia | 46.31439 | 49.31854 | 51.56322 | 54.66364 | 57.31927 | 59.61056 | 62.61794 | 64.85118 | 66.53721 | 68.02052 | 69.23388 | 70.72848 |
| Europe | 64.40850 | 66.70307 | 68.53923 | 69.73760 | 70.77503 | 71.93777 | 72.80640 | 73.64217 | 74.44010 | 75.50517 | 76.70060 | 77.64860 |
| Africa | 39.13550 | 41.26635 | 43.31944 | 45.33454 | 47.45094 | 49.58042 | 51.59287 | 53.34479 | 53.62958 | 53.59827 | 53.32523 | 54.80604 |
| Americas | 53.27984 | 55.96028 | 58.39876 | 60.41092 | 62.39492 | 64.39156 | 66.22884 | 68.09072 | 69.56836 | 71.15048 | 72.42204 | 73.60812 |
| Oceania | 69.25500 | 70.29500 | 71.08500 | 71.31000 | 71.91000 | 72.85500 | 74.29000 | 75.32000 | 76.94500 | 78.19000 | 79.74000 | 80.71950 |
ggplot(ContinentMLE, aes(x=year, y=lifeExp, color=continent)) + geom_line() +
theme(axis.text.x =element_text(angle=45, hjust=1), plot.title = element_text(hjust = 0.5)) + labs(title = "Life Expectancies per Continent Since 1952", x="Year", y="Life Expectancy", color = "Continent")
All continents have increased life expectancies since 1952 with Oceania consistently having the highest MLE, and Africa having the lowest. Africa is the only continent which has not increased steadily, and has had a plateau period between 1987 and 2002, but had an encouraging upturn in life expectancy between 2002 and 2007.