Let R fly: Visualizing Export Data using R

October 2, 2011

(This article was first published on nzprimarysectortrade » R related, and kindly contributed to R-bloggers)

Having been using R for 5+ years, visiting www.r-bloggers.com daily, learning cool tricks from it and knowing cool UseRs from it, I finally decide to quit being an observer and start to be a contributor to this wonderful community. In this very first of my blog, I would like to demonstrate how to use a very cool R GUI — RAnalyticFlow and three useful R packages — rworldmap, gregmisc and TeachingDemos to visualize New Zealand primary export data (the data used in this post are freely and publicly available from www.stats.govt.nz).

RAnalyticFlow is a free GUI for R. It lets you to create flow charts of R codes. I find it really useful to break down big chunks of R codes into small manageable pieces. It also allows you to put non-essential codes (plots or checking data) out of essential ones. Below is an example

I am not going to details about this GUI but I do encourage you to download and have a play (runs on Mac, Windows and Linux). It is addictive that I must warn you though. A little downside is that it only supports 32-bit R.  But the developers are approachable if you want a version that supports 64-bit.

My goal here is to plot two world maps that show

  1. what primary-sector-products have been exported to which countries for the year ended June 2011
  2. what is the change on last year

“rworldmap” package offers functionality to visualize data on a world map. “mapPies”  is fairly flexible function that is suitable for the first job. Forming the data is pretty straightforward, which I will skip here. One thing that I like to point out is that “trim” function from “gregmisc” package is a useful function to eliminate spaces ahead and at the rear of strings (worth to keep in your pocket).

After having the map plotted, I like to have some barplots on the map to display top 10 markets for each product. “subplot” function from “TeachingDemos” package plots basic R graphs on an existing plot for a given position. For the background of these barplots, I used “rect” function. The final product rolls out like below

The second job is to show the change in export revenue on last year. “mapBars” from “rworldmap” function offers the functionality to do that, but it plots bars as stacked vertical or horizontal rectangular, which is different from conventional bar plots as we expect. Instead, I used “subplot” and “barplot” functions to consummate the job. The final product of the second job goes like

To conclude, I’d like to encourage you to give a try on RAnalyticFlow and consider using “rworldmap” package when you have worldwide data to visualize.

To leave a comment for the author, please follow the link and comment on their blog: nzprimarysectortrade » R related.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Mango solutions

plotly webpage

dominolab webpage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training





CRC R books series

Six Sigma Online Training

Contact us if you wish to help support R-bloggers, and place your banner here.

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)