Data Studying and Examining Trade in Merchandise Using R

Posted on Nov 30, 2018
The skills the author demoed here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.


The purpose of this shiny app was to allow users to examine trade in merchandise data and 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 (WTO) website here. The dataset focuses on merchandise trade within a country. Some of the variables in the dataset include:

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

For ease of use, the data were constrained to 2015, and the categories of trade were derived from the nine major categories listed by the WTO here.

How to use the App:

Data Studying and Examining Trade in Merchandise Using R

After the app loads, you will be presented with a world map. This is the first of four page tabs. From there, you can switch to the other tabs "Country A", "Country B", and "Comparisons" by clicking on them.

Below the page tabs, there are two dropdown menus: "USD or Percentage of Trade" and "Flow of Trade". These two menus will transform what the map shows. In the picture above, Percentage of Trade and Exports are selected. In this case, the map shows the percentage of each country's trade that is exports. The darker shade of green, the higher the percentage of exports is for that particular country.

Under the second tab "Country A", you can examine an individual country's trade in merchandise. Countries can also be selected from the dropdown menus below the page tabs. (Because the lists contain over 200 countries, it is recommended that you type in the country you are interested in to ease the country selection process.) In the picture above, China was selected as Country A, and both Import and Exports (All) are included. This allows you to examine categories of Chinese trade in a bar graph. If you are interested in specific values, simply move the cursor over any bar to show the exact values.

Data Studying and Examining Trade in Merchandise Using R

Bottom of the Page

At the bottom of the page, there is a series of bar graphs that compare each merchandise category to the world average for that category. On the sidebar, there are nine checkboxes. The default is to show nine graphs, one for each category. However, because China does not trade in Agricultural Products, Other Manufactures, and Other Semi-Manufactures, these checkboxes can be used to limit the merchandise categories shown. Graphs will be added or removed accordingly.

The "Country B" tab functions exactly the same as the "Country A" tab, but it is controlled by the Country B dropdown menu.

Comparison Tab

The final page tab "Comparison" is a comparison of the percentage of trade between the two selected countries. (The selected countries are those selected using the Country A and Country B dropdown menus.)ย In the above photo, China and the United States are shown. ย To compare different countries, simply select different countries using the Country A and Country B dropdown menus on the sidebar.

Data Studying and Examining Trade in Merchandise Using R

At the bottom of "Comparisons" page, there is a series of bar graphs that compare each merchandise category of Country A to each merchandise category of Country B. Feel free to click around and see how it works!

Future Directions:

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

About Author

Devon Blumenthal

Prior to joining NYC Data Science Academy, Devon received his Masters in Measurement, Statistics, and Evaluation at the University of Maryland, College Park. As an instructor, he taught Introduction to Statistics and as a teaching assistant, he helped...
View all posts by Devon Blumenthal >

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI