-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
107 lines (82 loc) · 3.5 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
99
100
101
102
103
104
105
106
107
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(str = strOptions(strict.width = "cut"))
```
# worldbank
<!-- badges: start -->
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://github.com/m-muecke/worldbank/actions/workflows/R-CMD-check.yaml)
[](https://CRAN.R-project.org/package=worldbank)
<!-- badges: end -->
## Overview
worlbank provides a simple interface to the following [World Bank](https://datahelpdesk.worldbank.org/knowledgebase/articles/889386-developer-information-overview) APIs:
- [Indicators API v2](https://datahelpdesk.worldbank.org/knowledgebase/articles/889392-about-the-indicators-api-documentation)
- [Poverty and Inequality Platform (PIP) API](https://pip.worldbank.org/api).
- [Finances One API](https://financesone.worldbank.org)
The main difference to other packages is that it's a modern implementation using the [httr2](https://httr2.r-lib.org) package
and supports all available endpoints and parameters.
## Installation
You can install the released version of **worldbank** from [CRAN](https://CRAN.R-project.org) with:
```{r, eval = FALSE}
install.packages("worldbank")
```
And the development version from [GitHub](https://github.com/) with:
```{r, eval = FALSE}
# install.packages("pak")
pak::pak("m-muecke/worldbank")
```
## Usage
worldbank functions are prefixed with `wb_` and follow the naming convention of the [World Bank API v2](https://datahelpdesk.worldbank.org/knowledgebase/articles/889392-about-the-indicators-api-documentation).
```{r demo}
library(worldbank)
# filter by specific country
wb_country(c("US", "DE"))
# or fetch all (default)
country <- wb_country()
str(country)
# search for specific indicator
ind <- wb_indicator()
ind <- subset(
ind,
grepl("GDP", id, fixed = TRUE) & source_value == "World Development Indicators"
)
str(ind)
# fetch indicator data for specific or all countries (default)
gdp <- wb_data("NY.GDP.MKTP.CD", c("US", "DE", "FR", "CH", "JP"))
str(gdp)
```
```{r plotting, message = FALSE, echo = FALSE, dpi = 300}
library(ggplot2)
subset(gdp, date >= 1980) |>
ggplot(aes(x = date, y = value, color = country_name)) +
geom_line() +
theme_minimal() +
theme(
legend.title = element_blank(),
legend.position = "bottom",
plot.title = element_text(face = "bold"),
panel.grid.major.y = element_line(color = "black", linewidth = 0.2),
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
axis.text = element_text(color = "black"),
axis.title = element_blank()
) +
scale_y_continuous(
labels = scales::label_currency(scale_cut = scales::cut_short_scale())
) +
labs(title = "GDP in Current U.S. Dollars", color = "Country")
```
## Related work
* [WDI](https://github.com/vincentarelbundock/WDI): R package to download World Bank data
* [pipr](https://github.com/worldbank/pipr): R client for the PIP Worldbank API
* [wbstats](https://github.com/gshs-ornl/wbstats): R package for searching and downloading data from the World Bank API
* [wbwdi](https://github.com/tidy-intelligence/r-wbwdi): R package to download World Bank indicator data