Seamless analytical environment by WDI, dplyr, and rMaps

[This article was first published on My Life as a Mock Quant in English, 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.

Recently I found that My R Guru @ramnath_vaidya is developping a new visualization package rMaps.

I was so excited when I saw it for the first time and I think that it's really awesome for plotting any data on a map.

Let me explain how we can

  • Get data(WDI package)
  • Manipulate data(dplyr package)
  • Visualize the result(rMaps package)

with greate R packages.

Except for rMaps package, you can install these packages(WDI, dplyr) from CRAN by usual way.

install.packages(c("WDI", "dplyr"))<br />

To install rMaps package, you just write the following commands on R console.

require(devtools)<br />install_github("ramnathv/[email protected]")<br />install_github("ramnathv/rMaps")<br />

(Don't forget to install “devtools” package to use install_github function.)

Now, as an example, I show you that

  • Get “CO2 emissions (kt)” data from World Bank by WDI package
  • Summarze it to by dplyr package
  • Visualize it by rMaps package

The result is shown below:


By the way, recently an Japanese R professional guy often posts his greate articles. I recommend you to see these articles if you are interested in visualizing and dplyr especially.

Source codes:

library(WDI)<br />library(rMaps)<br />library(dplyr)<br />library(countrycode)<br /># Get CO2 emission data from World bank<br /># Data source :<br />df <- WDI(country=c("all"), <br />          indicator="EN.ATM.CO2E.KT", <br />          start=2004, end=2013)<br /># Data manipulation By dplyr<br />data <- df %.% <br />  na.omit() %.%<br />  #Add iso3c format country code <br />  mutate(iso3c=countrycode(iso2c, "iso2c", "iso3c")) %.% <br />  group_by(iso3c) %.%<br />  #Get the most recent CO2 emission data<br />  summarize(value=EN.ATM.CO2E.KT[which.max(year)])<br /># Visualize it by rMaps<br />i1 <- ichoropleth(value~iso3c, data, map="world")<br />i1$show("iframesrc", cdn = TRUE) # for blog post<br />#... or you can direct plot by just evaluating "i1" on R console.<br />

To leave a comment for the author, please follow the link and comment on their blog: My Life as a Mock Quant in English. 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)