A Simple Example on How to Use Quandl in R

Downloading the files from Quandl

less5dollars.br <- read.csv("http://www.quandl.com/api/v1/datasets/WORLDBANK/BRA_SI_POV_5DAY.csv?&auth_token=xTSoqJgfbiCgXu6xmdHp&trim_start=1994-12-31&trim_end=2009-12-31&sort_order=desc", 
    colClasses = c(Date = "Date"))
gini.br <- read.csv("http://www.quandl.com/api/v1/datasets/WORLDBANK/BRA_SI_POV_GINI.csv?&auth_token=xTSoqJgfbiCgXu6xmdHp&trim_start=1994-12-31&trim_end=2009-12-31&sort_order=desc", 
    colClasses = c(Date = "Date"))

Merging the datasets

names(less5dollars.br)[names(less5dollars.br) == "Value"] <- "less5dollars"
names(gini.br)[names(gini.br) == "Value"] <- "gini"
gini.br$Date <- as.Date(gini.br$Date, "%Y/%m/%d")
less5dollars.br$Date <- as.Date(less5dollars.br$Date, "%Y/%m/%d")


df <- merge(less5dollars.br, gini.br, by.x = c("Date"), incomparables = NA, 
    all.x = TRUE)

Plotting the graph

library(ggplot2)
library(ggthemes)

plot1 <- ggplot(df, aes(Date)) + geom_line(aes(y = less5dollars, colour = "< 5 US$/Day")) + 
    geom_line(aes(y = gini, colour = "Gini")) + xlab("") + ylab("") + theme_minimal() + 
    ggtitle("Population with Less than 5 Dollars A Day (%) & Gini Coefficient") + 
    theme(legend.title = element_blank())
plot1

plot of chunk plots