Examining Trade in Merchandise Using R

Devon Blumenthal
Posted on Nov 30, 2018


The purpose of this shiny app was to allow users to examine trade in merchandise information on a country-by-country basis.

You can find the app here and the code used to implement the app here.

The Data:

The dataset used was downloaded from the World Trade Organization's website here. The dataset focuses on Merchandise trade within a country. Some of the variables in the dataset include.

  • Country
  • Year
  • The category of trade
  • Whether the trade was an export or import
  • The amount traded, in millions USD.

For ease of use, the data was constrained to 2015, and the categories of trade were reduced from 30+ to 9 major categories listed by the WTO here.

How to use the App:

After the app loads, you will be created by a world map. You are currently looking at the first tab "World Map" out of four. You can switch to the other tabs Country A, Country B, and Comparisons.

Focusing on the first tab, the two handy dropdown lists are "USD or Percentage of Trade" and "Flow of Trade". These two lists will transform what the map shows. In the picture above, Percentage of Trade and Exports are selected from the lists. The map shows how much of of each country's trade is in exports. The darker shade of green, the higher the percentage of exports for that particular country.

Moving onto the second tab, we can now look at an individual country and examine its trade in merchandise. Countries can also be selected from the dropdown list. Because the list has over 200 countries, it is advised that you type in the country you are interested in. In the picture above China was selected, and we include both Import and Exports. We can now look at the categories of products China trades in with a bar graph. If we are interested in the specifics, we can place the cursor over any bar to show the exact amount.

At the bottom of the tab, there are a grid of graphs that compare each category to the world. On the left hand side, you will notice there are 9 checkboxes. The typical default is to show nine graphs, one for each category. However, we notice in the previous photo that China does not trade in Agricultural Products, Other Manufactures, and Other Semi-Manufactures. We can use these checkboxes to only show which variables w care about, and the graphs will be added or removed accordingly. The Country B tab is the same as Country A, only it is controlled by the Country B dropdown list.

The final tab is a comparison of two countries using bar graphs. For this example, China and the United States were chosen. What countries are shown are the ones that you have selected previously when looking at the Country tabs. Looking at and comparing different countries is as easy as just choosing a new country in the dropdown list.

The bottom of this tab works in the same way as the two country tabs. Feel free to click around and see how it works!

Future Directions:

  • The code that runs the data needs to be cleaned. There are a lot of code that can be simplified/removed.
  • Include more than just one year. This will allow for longitudinal trends to be shown.
  • The WTO website has a far greater and more in-depth dataset that includes transactions between countries. However the data is not very structured and would take hours to clean properly.

About Author

Devon Blumenthal

Devon Blumenthal

Prior to joining NYC Data Science Academy, Devon received his Masters in Measurement, Statistics, and Evaluation at the University of Maryland. As an instructor there he taught introduction to statistics to social science majors for and as a...
View all posts by Devon Blumenthal >

Leave a Comment

Your email address will not be published. Required fields are marked *

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags