World Bank API R package available!

[This article was first published on R-Chart, 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.

In previous posts I demonstrated R plots created using World Bank Data through their API.  The following is a much nicer example of what is possible.  Many thanks to Vincent Arel-Bundock for sharing his work to make the World Bank Development Indicator API data available as an R package!  He also provided comments in a previous post that show great examples of the use of the API (the results of which are pictured above).  
In only 4 lines of code, the graph above is created with data straight from the World Bank.  This example requires the ggplot2 library as well as the new WDI library.  WDI is used to return a data frame that is passed to ggplot to produce the graph. 

DF <- WDI(country=c("US","CA","MX"), indicator="NY.GDP.MKTP.KD.ZG", start=1990, end=2008)
ggplot(DF, aes(year, NY.GDP.MKTP.KD.ZG, color=country))+geom_line(stat=”identity”)+theme_bw()+xlab(“Year”)+opts(title=”Annual GDP Growth rate (%)”)+ylab(“”)

There is a reference manual that describes the use of ggplot2 in greater detail.  Oh – one other note.  I generally save charts using the png command.  This did not work with ggplot2, I needed to create the chart in R and then executed the following command:


To leave a comment for the author, please follow the link and comment on their blog: R-Chart. 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)