How to connect to Quandl with R
Quandl, now part of Nasdaq, provide structured data, primarily for finance and economic analysis, but have also categorized and structured data that is useful for a range of population and business analysis. Quandl’s service has structured this information from a range of traditional and alternative data suppliers
Some of the data available through Quandl comes at a cost, but they also provide a wide range of free data sets. For the purposes of this example, we’ll look at the growth in urban population in Canada using the World Bank World Development Indicators. The World Bank maintains it’s own online database and access tool at databank.worldbank.org , but Quandl does a great job of standardizing the dataset and making access easy along with a a range of other data sources
The first steps to access the quandl data are to create an account on quandl.com and save your API key, which can be found under Account Settings and Profile. Once that has been done you can install the quandl library from CRAN and set your API key
install.packages("Quandl")
library(Quandl)
Quandl.api_key('your_api_key')
with this setup, you then need to find the correct reference code to pull data from quandl. You can find this attached on the preview of the dataset within quandl
using this reference code, you can then pull information directly into your R environment
ca_urban_pop_data_annual=Quandl("WWDI/CAN_SP_URB_TOTL")
having this information downloaded we can now generate a quick chart of the data and use it in other analysis
library(ggplot2)
library(scales)
ca_urban_chart=ggplot(data=ca_urban_pop_data_annual)+
geom_line(aes(x=Date, y=Value), color="#4fbbbd", size=1)+
theme_minimal()+
scale_y_continuous(labels=comma)+
labs(title="",
subtitle="Canada Urban Population Growth 1950-2017",
x="",
y="")