1. Overview

The aim of this interactive visualisation is to shed light on the Life Expectancy across the globe and explore its relationship with GDP per Capita.

1.1 Data Source

The data set is obtained from the ‘gapminder’ package prepared by Gapminder.

1.2 Data and Design Challenges

Type Challenge Solution
Data Sourcing for relevant data sets and integrating them together poses a challenge Found the ‘gapminder’ package which provides all the data required
Data Getting the necessary columns to plot a choropleth map Use ‘gapminder’ package to retrieve more columns
Design Finding a suitable plot type that involves more variables for better insights Use a bubble chart along with time slider
Design No obvious distinction between the countries on choropleth map as colours are too similar for most countries Use diverging colour palette for choropleth map

1.3 Proposed Sketched Design

2. Data Visualization Step-by-Step

2.1 Install and Load R Packages

packages = c('plotly','gapminder','tidyverse')

for(p in packages){
  if(!require(p, character.only = T)){
    install.packages(p)
  }
  library(p, character.only = T)
}

2.2 Load Data from ‘gapminder’ Package

country_data <- gapminder
country_data
## # A tibble: 1,704 x 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.
##  2 Afghanistan Asia       1957    30.3  9240934      821.
##  3 Afghanistan Asia       1962    32.0 10267083      853.
##  4 Afghanistan Asia       1967    34.0 11537966      836.
##  5 Afghanistan Asia       1972    36.1 13079460      740.
##  6 Afghanistan Asia       1977    38.4 14880372      786.
##  7 Afghanistan Asia       1982    39.9 12881816      978.
##  8 Afghanistan Asia       1987    40.8 13867957      852.
##  9 Afghanistan Asia       1992    41.7 16317921      649.
## 10 Afghanistan Asia       1997    41.8 22227415      635.
## # … with 1,694 more rows

2.3 Visualise Bubble Chart of Life Expectancy against GDP per Capita by Continent/Country, 1952-2007

bubble <- country_data %>%
  plot_ly(
    x = ~gdpPercap, 
    y = ~lifeExp, 
    color = ~continent, 
    size = ~pop, 
    frame = ~year, 
    text = ~country,
    hoverinfo = ~text,
    type = 'scatter',
    mode = 'markers'
  ) %>% layout(
    title = "Life Expectancy against GDP per Capita by Continent/Country, 1952-2007",
    xaxis = list(
      title = "GDP per Capita",
      type = "log"
    ),
    yaxis = list(
      title = "Life Expectancy",
      range = c(0,90)
    )
  ) %>% animation_slider(
    currentvalue = list(
      prefix = "Year: ", 
      font = list(color="skyblue")
    )
  )

bubble

2.4 Prepare Data for Choropleth Map

gapminder_codes <- gapminder::country_codes

gapminder_unfiltered <-gapminder::gapminder_unfiltered

# We join both datasets with inner_join to get a dataset with the info by country, continent and country-code

gapminder_join <- gapminder_unfiltered %>%
  inner_join(gapminder_codes, by= "country") %>%
  mutate(code = iso_alpha)

gapminder_data <- gapminder_join %>%
  inner_join(maps::iso3166 %>%
               select(a3, mapname), by= c(code = "a3")) %>%
  mutate

gapminder_data
## # A tibble: 3,584 x 10
##    country     continent  year lifeExp     pop gdpPercap iso_alpha iso_num code 
##    <chr>       <fct>     <int>   <dbl>   <int>     <dbl> <chr>       <int> <chr>
##  1 Afghanistan Asia       1952    28.8  8.43e6      779. AFG             4 AFG  
##  2 Afghanistan Asia       1957    30.3  9.24e6      821. AFG             4 AFG  
##  3 Afghanistan Asia       1962    32.0  1.03e7      853. AFG             4 AFG  
##  4 Afghanistan Asia       1967    34.0  1.15e7      836. AFG             4 AFG  
##  5 Afghanistan Asia       1972    36.1  1.31e7      740. AFG             4 AFG  
##  6 Afghanistan Asia       1977    38.4  1.49e7      786. AFG             4 AFG  
##  7 Afghanistan Asia       1982    39.9  1.29e7      978. AFG             4 AFG  
##  8 Afghanistan Asia       1987    40.8  1.39e7      852. AFG             4 AFG  
##  9 Afghanistan Asia       1992    41.7  1.63e7      649. AFG             4 AFG  
## 10 Afghanistan Asia       1997    41.8  2.22e7      635. AFG             4 AFG  
## # … with 3,574 more rows, and 1 more variable: mapname <chr>

2.5 Get World Map Data

world_map <- map_data("world") %>%
  filter(region != "Antartica")

2.6 Visualise Choropleth World Map for Life Expectancy in 2007

gapminder_life_exp <- gapminder_data %>%
  filter(year == 2007) %>%
  select(mapname, code, lifeExp)

map <- plot_geo(gapminder_life_exp) %>%
  add_trace(
    z = ~lifeExp,
    color = ~lifeExp,
    colors = 'RdBu',
    text = ~mapname,
    locations = ~code
  ) %>%
  colorbar(title = "Years") %>%
  layout(title = 'Life Expectancy around the World, 2007',
         geo = gapminder_life_exp
  )

map

3. Final Data Visualization

bubble
map

For Identifying the Continents:

3.1 Purpose of Visualizations

The top visualization is a bubble chart which reveals the life expectancy against GDP per capita ratio by each continent and country (tooltip). Additional information like the population size of the country is reflected in the size of the bubble as well. An interactive timeline slider is also provided for readers to toggle and observe the shift across the years.

The bottom visualization focuses on life expectancy of countries across the globe, highlighting the continents with high/low life expectancy. Through the comparison with the map of the continents, readers can get a good sensing of the general life expectancy of the continents as well.

3.2 Derived Insights

  1. From 1952 to 2007, most countries increase in life expectancy and GDP per capita as seen by the general shift towards the top-right of the plot over the years.
  2. Life expectancy positively correlates with GDP per capita as the best fit line would likely be of a positive gradient judging by the points on the plot. This is reasonable as higher GDP per capita suggests a better economy and that likely means better hygiene, sanitation and medical services in the country which should reflect higher life expectancy.
  3. Africa is the continent with the lowest life expectancy and GDP per capita as seen from the darker green cluster at the bottom-left of the bubble chart whereas Oceania is the highest for both as seen from the light green cluster at the top-right.These observations are consistent even across the years.
  4. Asia made the most significant improvement in life expectancy and GDP per capita as the purple cluster has the largest magnitude of shift towards the top-right from 1952 to 2007.
  5. Australia/Oceania, Europe and North America have high life expectancy of about 80 years as seen from the dark blue regions whereas Africa, especially the southern part has very low life expectancy of about 40-50 years as seen from the red regions.