Want to see the code?

A version of this page showing the code is available here.

Background Information

The Gross Domestic Product (GDP) of a country has four components: private consumption (private spending on goods and services), investment, net exports (total exports minus total imports), and government spending (public spending on goods and services).

On the second plot, each of the four components are shown for each year as a proportion of the whole GDP. For a given year, the four proportions add up to one.

Notice that net exports is sometimes negative. This means that, in that year, the value of the imports into the USA was greater than the value of the exports out of the USA, otherwise known as a trade deficit.

Visualizations

Data Source

The data was collected by the United States Bureau of Labor Statistics. It was downloaded from the United States Bureau of Economic Analysis website, here.

Reflection

One idea from Wilke’s book that I took into consideration was Chapter 10 on visualizing proportions. My original idea for this data was to show a pie chart for each year. However, I realized that that wouldn’t be the best idea in this situation. I also considered using stacked bars instead of grouped bars. This was not feasible due to net exports being negative for many of the years.

An additional thing that I would like to do with this data is to make similar visualizations for the real GDP, rather than just the nominal GDP. Real GDP adjusts the GDP for inflation because, of course, prices have increased signficantly since 1929, the first year of the data.

One technical challenge that I had was creating the buttons. It was difficult to get them in the right spot and to have them change the right aspects of the plot. In general, placement of the different objects on the plot was a bit weird. The scale for x and y arguments in Plotly is [-2, 3]. I’d like to hear the rationale for that scale.