Let R fly: Visualizing Export Data using R

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.

About these ads

About xingmowang

to be added
This entry was posted in R related. Bookmark the permalink.

8 Responses to Let R fly: Visualizing Export Data using R

  1. Pingback: Let R fly: Visualizing Export Data using R | R | Scoop.it

  2. Ruben Garcia says:

    Hi there,
    thank you for the posting. Really interesting to find out about the GUI and those packages.
    Is there any chance that you could post some sample code as well?

  3. Hey Xingmowang,

    Appreciate your post. I didn’t know about RAnalyticFlow. Will surely check it out and download it to my PC. And yes, do post your code. Only been using R for a few months now, so I am sure I will learn from looking at the code.
    Ram

  4. Ruben Garcia says:

    That sounds great!
    I’m looking forward to it.
    Thanks a lot

  5. xingmowang says:

    Tutorial on its way. Really appreciate your comments.

  6. Christer says:

    Awesome charts. I hope you will provide some code on how they were created. I have used RAnalyticFlow myself and like it a lot.
    Christer

  7. Jorge de la Vega says:

    Dear Xingmowang:
    Very nice and informative graphs. I knew the existance of RAnalyticFlow but it was in it early stages and only windows version was available. Your blog is now on my daily readig list, waiting to get some code examples.
    Have a great day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s