-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
98 lines (66 loc) · 3.28 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE, warning=FALSE, message=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
message = FALSE,
warning = FALSE,
comment = "#>",
fig.path = "README-"
)
library(FromQuandl)
library(Quandl)
library(ggplot2)
library(dplyr)
library(ggthemes)
Quandl.api_key("wNTJQSHWqSsKsDQprJhb")
```
# FromQuandl
<!-- badges: start -->
[![Travis build status](https://travis-ci.com/Reckziegel/FromQuandl.svg?branch=master)](https://travis-ci.com/Reckziegel/FromQuandl)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/Reckziegel/FromQuandl?branch=master&svg=true)](https://ci.appveyor.com/project/Reckziegel/FromQuandl)
[![R-CMD-check](https://github.com/Reckziegel/FromQuandl/workflows/R-CMD-check/badge.svg)](https://github.com/Reckziegel/FromQuandl/actions)
[![Codecov test coverage](https://codecov.io/gh/Reckziegel/FromQuandl/branch/master/graph/badge.svg)](https://codecov.io/gh/Reckziegel/FromQuandl?branch=master)
<!-- badges: end -->
The goal of `FromQuandl` is to easy the search, download and data preprocessing steps that often happens when using the `Quandl` package in R.
Currently supports functions for `IMF`, `World Bank` and `Yale Department of Economics` datasets.
## Installation
You can install FromQuandl from github with:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("Reckziegel/FromQuandl")
```
## Examples
Suppose you would like to download the Current Account Balance (as % of GDP) for all countries of a specific region or with similar economic characteristics, like the G7. Use the `fq_imf_search()` function to discover the Current Account code in `Quandl`.
```{r}
fq_imf_search('account')
```
Next use `fq_imf()` to download and plot the data.
```{r message=FALSE, warning=FALSE}
ca <- fq_imf(countries = 'g7', indicators = 'BCA_NGDPD', start_date = '2005-01-01')
ca
ca %>%
ggplot(aes(x = date, y = value, color = country)) +
geom_line(size = 1, show.legend = FALSE) +
geom_hline(aes(yintercept = 0), color = 'red', linetype = 'dashed', alpha = 0.3) +
facet_wrap(~country, scale = "free_y") +
labs(title = "Current Account Balance (% of GDP)",
subtitle = "G7 Countries From 2005-01-01 through 2020-12-01",
caption = "Source: International Monetary Found (IMF), Quandl.com.") +
theme_fivethirtyeight() +
scale_color_gdocs()
```
The result is a `tibble` that it's ready to be used in `ggplot2`.
There is no need to restrict the download to only one indicator. The `indicators` argument supports lists and vectors of strings as well, but be aware that may be safe using `Quandl.api_key()` if you want to access several time series at once.
As a second example imagine that you want to download the rate of change in poverty statistics from the World Bank for all countries in the Commonwealth of Independent States. Simply run
```{r}
#library(FromQuandl)
# get poverty codes
poverty_data <- fq_wb_search('poverty')
# download data
fq_wb(countries = 'cis', indicators = poverty_data$code, transform = 'rdiff')
```
The data is tidy and ready to be used with the `%>%` operator.
Additional information about the `fq_imf()`, `fq_wb()` and `fq_yale()` can be found at the package documentation.