World Bank API R package available!

June 23, 2010

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

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 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.


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)