Time series
A time series consists of measurements of the same variable at different time points. Most of the tables from Statistics Netherlands are revised monthly, quarterly or yearly. This tutorial explains how to process and visualise time series using data about tourist accommodation tax ("toeristenbelasting") as an example. The prerequisites for this tutorial are covered in the Quick start guide.
The code examples can be copied easily to the clipboard by clicking the "Copy" button in the code block. The Dutch versions of these examples have been combined into a GitHub repository.
Pick a programming language:
Table 84120NED contains data about the government tax revenue in the Netherlands. The dataset contains various taxes; the tax code corresponding to tourist tax can be found in the metadata.
The Key
corresponding to tourist tax is A045081. To retrieve the subset of the table with information about this tax we add the optional parameter BelastingenEnWettelijkePremies = "A045081"
to cbs_get_data()
.
The response from the API has a column Perioden which contains time periods in the format yyyyXXww
, where yyyy
are years, XX
denotes whether these are numbers about a year (JJ
), quarter (KW
) or month (MM
) and ww
is the index number. This period can be transformed with cbs_add_date_column()
, adding a column Perioden_freq
with the type of period (month/quarter/year) and another column with the start date of the period. Annual figures get assigned the letter Y
in Perioden_freq
. Hence it is easy to filter for annual figures by applying filter(Perioden_freq == "Y")
.
ggplot2
.
Table 84120NED contains data about the government tax revenue in the Netherlands. The dataset contains various taxes; the tax code corresponding to tourist tax can be found in the metadata.
The Key
corresponding to tourist tax is A045081. To retrieve the subset of the table with information about this tax we add the filter "BelastingenEnWettelijkePremies eq 'A045081'""
to get_data()
.
Annual figures can be filtered with the regular expression ^\d{4}$
, which checks whether a string consists of precisly four digits.
matplotlib
.