Maize trade Part I: Generate the network diagram

[This article was first published on StaTEAstics., and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

It has been several month since my last post, partially due to the fact that my laptop was lost and several deadlines was approaching. Fortunately I will be returning to Taiwan and get a new laptop within a week, and will be updating regularly again.

This post will provide a brief peak of the trade network which will be presented in the new FAO statistical yearbook 2013. The data area available from FAOSTAT (http://faostat3.fao.org/home/index.html#DOWNLOAD) under the "trade" and "detail trade matrix"section.

From the plot we can see that the United States of America is the biggest exporter of maize and Japan is the biggest importer as indicated by the size of the arrow which represents the size of trade. Argentina, Brazil, Hungary and France are also major exporters. This is an improvement from previous analysis and graphics where only bi-lateral relationship or aggregated time series were shown.

Instead of the igraph package, I have used the network package to generate the network this time. The code is much simpler and it  is also more integrated with the sna package for conducting analysis.

<br />## Load required library<br />library(plyr)<br />library(network)<br /><br />## Read in data<br />maize.df = read.csv("https://dl.dropbox.com/u/18161931/maize_trade.csv", header = TRUE,<br />    stringsAsFactors = FALSE)<br /><br />## Present only the top 80% of the value traded to avoid over plotting.<br />maizeEx.df$cs = cumsum(maizeEx.df$Maize)<br />maizeFinal.df = subset(maizeEx.df, cs < tail(maizeEx.df$cs, 1) * 0.8)<br /><br />## Create the network and set the size of arrow<br />maizeFinal.df$edgeSize = with(maizeFinal.df, Maize/sum(Maize))<br />maizeFinal.df$arrowSize = ifelse(maizeFinal.df$edgeSize * 30 < 0.5 , 0.5,<br />    maizeFinal.df$edgeSize * 15)<br />maize.net = network(maizeFinal.df[, 1:2])<br /><br />## Plot the network<br />plot(maize.net, displaylabels = TRUE, label.col = "steelblue",<br />     edge.lwd = c(maizeFinal.df$edgeSize) * 100,<br />     arrowhead.cex = c(maizeFinal.df$arrowSize),<br />     label.cex = 2, vertex.border = "white",<br />     vertex.col = "skyblue", edge.col = rgb(0, 0, 0, alpha = 0.5))<br />

To leave a comment for the author, please follow the link and comment on their blog: StaTEAstics..

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)