I originally started this project as a part of my Codecademy online learning. It was called "Data Visualization Portfolio Project" and the topic was, as you have probably guessed, "Life expectancy and GDP". However, the provided dataset was tiny and outdated (there were data for only six countries over the span of 16 years, ending in the year 2015). So, I decided to get a full dataset. And, since I wanted to create interactive plots (above all, the famous gapminder-style bubble plot), I learned how to use a new Python library called Plotly.
All plots are interactive. In particular, you can click on the world region in the legend to hide all data related to that region.
The dataset and its limitations
I downloaded the dataset from ourworldindata.org. The countries in the dataset are divided into "world regions". As we will use this division to organize the data, let us start by depicting the regions on the map.
The dataset ends in year 2023, but goes very far back into the history. Let us look at the number of datapoints per world region, starting from the year 1200.
We can see that the data become more consistent somewhere around 1800–1850, depending on the region. I decided to start most of my analysis in the year 1848, because it is the year when a big wave of revolutions spread across Europe.
Note the big jump in the amount of data available between 1949 and 1950, after which the number of datapoints stabilizes. We can also see that there is a drop in year 2023, probably caused by not all the data being available at the time of the collection. Therefore, some of the analysis is only done for the time period 1950–2022. For the plots that depict the situation for a longer period, keep in mind that the data are less reliable prior to 1950.
So far we have only looked at any sort of data that we have for the given year and country. However, we are interested in three numbers:
- GDP per capita: average economic output per person in a country per year, adjusted for inflation and differences in living costs between countries, expressed in international-$ in 2011 prices;
- Life expectancy at birth: the number of years the average person born in a certain year would live if they experienced the same chances of dying at each age as people did that year;
- Population: based on data and estimates from different sources.
In the plot below, you can see that some data might be missing (most commonly the GDP), even when looking at year 2020.
We can (and do) fill most of the gaps by considering the last known value. For example, the life expectancy at birth in Canada between 1851 and 1901 has only one datapoint every 10 years. So we fill in the data for the years 1852 to 1860 with the value from 1851, years 1862 to 1870 with the value from 1861, and so on. (Another option would be to extrapolate the data linearly from the known endpoints, but the differences in the values are usually small, so I decided to go for the simpler approach.) However, some data might be still missing: the main example is Oceania, where the dataset contains GDP per capita only for Australia and New Zealand.
Finally, we need to deal with countries that significantly changed their borders. Since there were many countries like that since 1848, I will only focus on the major ones: USSR, India, Yugoslavia, Germany, and Czechoslovakia (I am Czech, so I had to include the last one). This is important, since the dataset contains data both for the USSR and Russia for most years; thus, when we aggregate the data, we would be counting Russia twice.
- USSR: We consider the USSR as one country for the time period 1922–1991, and as 15 separate countries otherwise.
- India, Yugoslavia: In these two cases, the dataset contains separate data for each country these blocks fell apart into, so we consider them separately. In particular, India never contains the area of Pakistan and Bangladesh, and Yugoslavia does not appear in the data at all.
- Germany: The dataset does not distinguish between West and East Germany.
- Czechoslovakia: Treated as one country until 1992, and as two separate countries (Czechia and Slovakia) since 1993.
Bubbles
We start with the "Gapminder-style" bubble graph that shows the relation of the GDP per capita with the life expectancy at birth. Additionally, the size of the bubble represents the size of the population.
There is a clear trend of the world getting richer and people living longer. Of course, some world regions (like Europe and North America) are richer than others (Africa). It is interesting that Asia contains both one of the wealthiest as well as one of the poorest countries in the world.
One country that significantly defies the trend of increasing wealth is Venezuela: its GDP increased from $2,000 in 1915 to $18,000 in 2012, but then it quickly dropped to $7,000 in 2019, and then even lower during the Covid-19 pandemic.
Looking at the last ten years, there are two obvious outliers: on the wealthy side, there is Qatar with almost triple the GDP per capita of the United States. On the other side, there is the Central African Republic with its GDP per capita about $600 (that is less than $1.7 per day!). The life expectancy of the Central African Republic in the dataset is very changeable and likely incorrect; WHO provides much more stable data ranging between 49 and 53 in the same period. Looking at the previous century, there is another noticeable outlier on the life-expectancy scale: the USSR; however, we will discuss it later.
Note that in the bubble graph, we need all three values (GDP per capita, Life expectancy at birth, and Population size) to be known in order for the country to appear in the plot. The value that is missing the most in the dataset (even after extrapolating from the known data) is the GDP per capita. Therefore, we will look at the Life expectancy and the Population separately.
Life expectancy
We want to compare the life expectancy at birth by world region. To get the value for the entire region, we compute the weighted average: \[ \frac{ \sum\limits_{\text{country}\ \in\ \text{region}} (\text{\small life expectancy in the country})\cdot(\text{\small population of the country}) } { (\text{\small total population of the region}) } \]
You may notice the big improvement of the life expectancy in Europe between 1991 and 1993. It is caused by the collapse of the Soviet Union (USSR); the Soviet Union as a whole is considered as part of Europe in the dataset, while some of the successor states belong to Asia. Hence, Europe "lost" a significant amount of inhabitants with lower life expectancy. In particular, in 1992, the (weighted average) life expectancy in the European part of the former USSR was 68.2 years, while in the Asian part it was only 64.2 years. However, the main reason is the low life expectancy in the USSR in the dataset: it is constant 36.4 years for the entire existence of the USSR (i.e., the original dataset contained the life expectancy for the USSR only for the year 1922, so we filled-in the same number until the year 1991). Of course, this value is not representative at all.
We can see that the overall trend is that the life expectancy increases over time, with noticeable set-backs during the first and the second world war, as well as the Great Chinese Famine affecting Asia in 1959–1961. Another (smaller) dip is visible in 2021, this one affecting all the world regions. Of course, this one was caused by the Covid-19 pandemic. (I plan to do another project that will dig deeper into this.)
To see the development of the life expectancy in more detail, we depict it in histograms. Note that the anomalous life expectancy in the USSR is clearly visible in the histogram for Europe.
Population growth
Finally, a nice and fun way to look at the population growth in the various world regions is a "bar chart race".
Growing up in central Europe, I heard a lot the narrative that the population of Africa is growing quickly. This chart shows that while there is some truth behind it (Africa's population surpassed Europe's in 1995), it is not the whole story. Not many people realize that more than half of the world population lives in Asia — which, as we have seen, contains both one of the richest and one of the poorest countries in the world.
The Python code is available on my Github repository.