The data for this analysis comes from the Gapminder Foundation’s database of statistics on various countries. The database includes variables such as the life expectancy of the country’s citizens, the fertility rate of the country, the population of the country, the infant mortality rate of the country, the GDP of the country, and the continent to which the country belongs.
The graph presents the relationship between the fertility rate and the life expectancy of the countries of the world for the year 2000. Each point on the graph is scaled according to the population of the country and colored according to the continent to which the country belongs. The graph helps to make evident the relationship between fertility rates and life expectancy within the countries of the world, and how that relationship is somewhat different according to the region of the world to which the country belongs. Unlike the examples used within the lecture notes, however, this example uses only data from a single year, and utilizes the population of the countries as one of the visual elements of the graph.
library(dslabs) library(dplyr)
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
continent_colors <-c("Africa"="#E05C2A", "Americas"="#3A7FC1", "Asia"="#2E9E6B","Europe"="#7B5EA7", "Oceania"="#C9A020")ggplot(data = gapminder_2000, aes(x = fertility, y = life_expectancy, color = continent, size = population )) +geom_point(alpha =0.72) +scale_size_continuous(name ="Population",range =c(1.5, 18),labels =label_comma(scale =1e-6, suffix ="M") ) +scale_color_manual(name ="Continent",values = continent_colors ) +labs(title ="Fertility Rate vs. Life Expectancy by Country (Year 2000)",subtitle ="Bubble size reflects total population; color indicates continent",x ="Fertility Rate (avg. children per woman)",y ="Life Expectancy (years)",caption ="Source: Gapminder dataset via dslabs package" ) +theme_minimal(base_size =13) +theme(plot.title =element_text(face ="bold", size =15, margin =margin(b =4)),plot.subtitle =element_text(size =11, color ="gray40", margin =margin(b =12)),plot.caption =element_text(size =9, color ="gray55", hjust =1),axis.title =element_text(size =12),legend.position ="right",legend.title =element_text(face ="bold", size =10),panel.grid.minor =element_blank(), panel.grid.major =element_line(color ="gray88"), plot.margin =margin(12, 16, 12, 12) )
Summary
The transition of these different populations is clearly visible within the graph. Countries with high rates of fertility (above 5 children per woman) have low life spans and are almost all located within Africa. As the fertility rates of a group of countries decreases, the life span of those individuals increases. The European countries have low fertility rates and high life spans. The Asian and American countries are of varying rates and life spans. Finally, the largest populations have some of the middle life spans and fertility rates. This demonstrates the second stage of demographic transition in which the mortality rate of a population decreases along with the fertility of that population.