The Central Bank of Brazil (BCB) offers access to its SGS system (sistema gerenciador de series temporais) with a official API available here.
Package GetBCBData offers a R interface to the API and many other advantages:
memoise
to speed up
repeated requests of data;Let’s have a look at unemployment rates around the world. After
searching for the ids in the SGS
system, we find the ids for 6 countries and set it as input
id
.
Now, lets download the data with GetBCBData
:
library(GetBCBData)
library(dplyr)
library(ggplot2)
<- c('Germany', 'Canada', 'USA',
my.countries 'France', 'Italy', 'Japan')
<- c(3785:3790)
my.ids
names(my.ids) <- paste0('Unemp. rate - ', my.countries)
<- gbcbd_get_series(id = my.ids ,
df.bcb first.date = '2000-01-01',
last.date = Sys.Date(),
format.data = 'long',
use.memoise = TRUE,
cache.path = tempdir(), # use tempdir for cache folder
do.parallel = FALSE)
glimpse(df.bcb)
<- ggplot(df.bcb, aes(x = ref.date, y = value) ) +
p geom_line() +
labs(title = 'Unemploymnent Rates Around the World',
subtitle = paste0(min(df.bcb$ref.date), ' to ', max(df.bcb$ref.date)),
x = '', y = 'Percentage*100') + facet_wrap(~series.name)
print(p)