tidyBdE is an API package that helps to retrieve data from Banco de España. The data is returned as a tibble, and the package automatically infers the format of each time-series (dates, characters, and numbers).
Banco de España (BdE) provides several time-series, either produced by the institution itself or compiled from other sources, such as Eurostat or INE.
The basic entry points for searching time-series are the catalogs (indexes). You can search for any series by name:
library(tidyBdE)
library(ggplot2)
library(dplyr)
library(tidyr)
# Search GBP on "TC" (exchange rate) catalog
xr_gbp <- bde_catalog_search("GBP", catalog = "TC")
xr_gbp |>
select(Numero_secuencial, Descripcion_de_la_serie) |>
# To table on document
knitr::kable()| Numero_secuencial | Descripcion_de_la_serie |
|---|---|
| 573214 | Tipo de cambio. Libras esterlinas por euro (GBP/EUR).Datos diarios |
Note: BdE files are currently provided only in Spanish, as the institution works on an English version. Search terms should be provided in Spanish to obtain results.
Once you have found your series, you can load the GBP/EUR exchange
rate using the sequential number reference
(Numero_Secuencial):
The package also provides a custom ggplot2 theme based on BdE’s publications:
ggplot(time_series, aes(x = Date, y = EUR_GBP_XR)) +
geom_line(colour = bde_tidy_palettes(n = 1)) +
geom_smooth(method = "gam", colour = bde_tidy_palettes(n = 2)[2]) +
labs(
title = "EUR/GBP Exchange Rate (2010-2020)",
subtitle = "%",
caption = "Source: BdE"
) +
geom_vline(
xintercept = as.Date("2016-06-23"),
linetype = "dotted"
) +
geom_label(aes(
x = as.Date("2016-06-23"),
y = 0.95,
label = "Brexit"
)) +
coord_cartesian(ylim = c(0.7, 1)) +
theme_tidybde()EUR/GBP Exchange Rate (2010-2020)
The package also provides convenience functions for a selection of the most relevant macroeconomic series, eliminating the need for manual searching:
# Data in "long" format
plotseries <- bde_ind_gdp_var("GDP YoY", out_format = "long") |>
bind_rows(
bde_ind_unemployment_rate("Unemployment Rate", out_format = "long")
) |>
drop_na() |>
filter(Date >= "2010-01-01" & Date <= "2019-12-31")
ggplot(plotseries, aes(x = Date, y = serie_value)) +
geom_line(aes(color = serie_name), linewidth = 1) +
labs(
title = "Spanish Economic Indicators (2010-2019)",
subtitle = "%",
caption = "Source: BdE"
) +
theme_tidybde() +
scale_color_bde_d(palette = "bde_vivid_pal") # Custom palette on the packageSpanish Economic Indicators (2010-2019)
You can use tidyBdE to create your own local repository at a given local directory passing the following option:
When this option is set, tidyBdE will look for
cached files in the bde_cache_dir directory and load them,
speeding up data retrieval.
It is possible to update the data (i.e. after every monthly or quarterly data release) with the following commands: