<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/nafta-trade-dashboard-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.enelmargen.org/tradewatch/intro/"> En El Margen - R-English</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong>Tradewatch</strong> is a dashboard, written in <strong>R</strong> using the <a rel="nofollow" href="http://rmarkdown.rstudio.com/flexdashboard/" target="_blank">flexdashboard</a> framework. Visualizations are made possible thanks to <a rel="nofollow" href="http://jkunst.com/highcharter/index.html" target="_blank">highcharter</a> and other packages.</p>
<p>The main purpose of the dashboard is to monitor trade, mostly from the Mexican perspective, of goods and commodities with countries that are in NAFTA.</p>
<p>In the age of fake news and policy-by-twitter, hopefully this tool will help guide more informed debate (and decisions) with respect to trade between these three countries.</p>
<h2>Notes and methodology</h2>
<p>The dashboard consists of basically three sections:</p>
<ul>
<li><strong>Bilateral Trade</strong>: These contain two, side-by-side comparisons, of exports and imports of products at a 2-level HS code depth. The color denotes year-over-year growth rate, while the size is related to the dollar value (in the newest month) of exports. The average growth rate for 2 digit codes is a weighted-mean of each 4-digit classification.</li>
<li><strong>US Share-shift:</strong> A visualization that describes the shift in share in the U.S. market of Mexican goods relative to Canadian goods. When the shift is lower than 0, Mexican imports lost share (vs. Canada last year) in the United States, and vice-versa. <em>Important caveat: the share is calculated only for goods from Mexico or Canada (Because they are not collectively exhaustive, it is perfectly posible that <strong>both</strong> lost share against a third competitor)</em></li>
<li><strong>Terms of Trade &amp; Fx:</strong> Prices are important. This section aims to gauge the impact of prices in the trade dynamic. To obtain exchange rates, I use the <a rel="nofollow" href="https://cran.r-project.org/web/packages/tidyquant/index.html" target="_blank">tidyquant package</a>. The other indexes refer to the price index of products imported from each of those countries.</li>
</ul>
<p><em>The names of HS Codes have been abbreviated manually, they can be found <a rel="nofollow" href="http://www.enelmargen.org/tradewatch/intro/" target="_blank">here</a>, however the code is still in between parenthesis. Should you want to look it up further, I recommend the UN Comtrade website</em></p>
<h2>Suggestions</h2>
<p>This release is a first and <em>fast</em> dive into the data, so I would be happy to listen to improvements to the tool, including some new indicators I haven’t added. <em>FYI, I tried to build the export matrixes at a 4-level granularity, but highcharts couldn’t handle it, any suggestions on how to do it would be welcome.</em></p>
<p>You can contact me via <a rel="nofollow" href="https://twitter.com/eflores89" target="_blank">twitter</a> or at my blog’s <a rel="nofollow" href="https://github.com/Eflores89/Eflores89.github.io/issues" target="_blank">issue</a> page.</p>
<h2>Dashboards</h2>
<p>The newest I could build is from november 2016, which is the month all three countries have statistics ready.</p>
<ul>
<li><a rel="nofollow" href="http://enelmargen.org/tradewatch/tw201611.html" target="_blank">November 2016</a></li>
</ul>
<h2>Code</h2>
<p>The code used to build the dashboard consists of two files: a <strong>functions.R</strong> file that contains some functions for downloading and cleaning the data and a <strong>db.Rmd</strong> file that builds the dashboard using the <em>knitr/flexdashboard</em> process in RStudio.</p>
<p>Both of these files can be found <a rel="nofollow" href="http://enelmargen.org/tradewatch/functions.R" target="_blank">here</a> and <a rel="nofollow" href="http://enelmargen.org/tradewatch/db.Rmd" target="_blank">here</a>.</p>
<p>FYI, I borrowed heavily from <a rel="nofollow" href="https://comtrade.un.org/data/Doc/api/ex/r" target="_blank">here</a> and <a rel="nofollow" href="https://gist.github.com/guillgall/3b979b59e8905ef7f244" target="_blank">here</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.enelmargen.org/tradewatch/intro/"> En El Margen - R-English</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/EGH7OMCLNMQ" height="1"></a></div>