--- title: "BOJ" author: "Stefan Angrick" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{BOJ} %\VignetteEngine{knitr::rmarkdown} \usepackage[utf8]{inputenc} --- ```{r setup, echo = FALSE} knitr::opts_chunk$set( message = FALSE, warning = FALSE, collapse = TRUE, fig.width = 6, fig.height = 4 ) ``` The `BOJ` package provides an `R` interface to [Bank of Japan](https://www.boj.or.jp/) statistics, specifically the [flat files](https://www.stat-search.boj.or.jp/info/dload_en.html) available on the [BOJ Time-Series Data](https://www.stat-search.boj.or.jp/) portal. ## Import data To import data, first load the package: ```{r loading} library("BOJ") ``` Next, run the `get_boj_datasets()` function to obtain a list of available data sets: ```{r datasets, message=FALSE, warning=FALSE} datasets <- get_boj_datasets() datasets ``` The function returns a [tibble](https://tibble.tidyverse.org/) data frame listing the available data sets. The column `url` can be used as input for the function `get_boj()` which downloads, parses and imports the corresponding data. To import monthly-frequency data on Japan's [Services Producer Price Index](https://www.boj.or.jp/en/statistics/pi/sppi_2015/index.htm/), run: ```{r sppi, message=FALSE, warning=FALSE} sppi <- get_boj(datasets$url[(datasets$name == "sppi_m_en")]) sppi ``` To plot the data using [ggplot2](https://ggplot2.tidyverse.org), run the following: ```{r plot, message=FALSE, warning=FALSE} library("dplyr") library("ggplot2") library("zoo") sppi_plot <- subset(sppi, code %in% c("PRCS15_5200000000", "PRCS15_5200010001", "PRCS15_5200010002", "PRCS15_5200010003", "PRCS15_5200010004", "PRCS15_5200010005", "PRCS15_5200010006", "PRCS15_5200010007")) sppi_plot <- mutate(sppi_plot, date = as.Date(as.yearmon(date, format = "%Y%m"))) sppi_plot <- mutate(sppi_plot, struc = gsub("^Major group/ ", "", struc)) sppi_plot <- subset(sppi_plot, !is.na(obs_value)) ggplot(sppi_plot, aes(x = date, y = obs_value)) + geom_line(aes(colour = struc)) + labs(x = "Date", y = "Services Producer Price Index (2015 base)") + theme(legend.title = element_blank()) ``` Note that BOJ data sets come with a number of different time formats. The [zoo](https://cran.r-project.org/package=zoo) package (e.g. `as.yearmon()`) should be able to parse most formats. ## Note This package is in no way officially related to or endorsed by the [Bank of Japan](https://www.boj.or.jp/). It was inspired by the [BIS R package](https://github.com/expersso/BIS). Please don't abuse the BOJ's servers with unnecessary calls.