ggdemetra is an extension of
ggplot2 to add seasonal adjustment statistics to your plots. The seasonal adjustment process is done with RJDemetra that is an R interface to JDemetra+, the seasonal adjustment software officially recommended to the members of the European Statistical System (ESS) and the European System of Central Banks.
RJDemetra implements the two leading seasonal adjustment methods TRAMO/SEATS+ and X-12ARIMA/X-13ARIMA-SEATS.
There are 4 main functionnalities in
ggdemetra depending of what you want to add in the graphic:
geom_sa(): to add a time series compute during the seasonal adjustment (the trend, the seasonal adjusted time series, etc.).
geom_outliers(): to add the outliers used in the pre-adjustment process of the seasonal adjustment.
geom_arima(): to add the ARIMA model used in the pre-adjustment process of the seasonal adjustment.
geom_diagnostics(): to add a table containing some diagnostics on the seasonal adjustment process.
All the functions have some common parameters and especially those to defined the seasonal adjustment method:
methodis the method used for the seasonal adjustment: X-13ARIMA (
method = "x13", the default) or TRAMO-SEATS (
method = "tramoseats").
specis the seasonal adjustment specification. It can be the name of pre-defined specification (see
?RJDemetra::tramoseats) or a user-defined specification created by
frequencyis the frequency of the input time series. By default, the frequency is computed and a message is printed with the one chosen (use
message = FALSEto suppress this message).
In the following examples, the data used is the French industrial production index. By default, the seasonal adjustment will then be processed with X-13ARIMA with a pre-defined specification
"RSA5c (automatic log detection, automatic ARIMA and outliers detection and trading day and easter adjustment). However, in the industrial production the working day effect has more economic sense than the trading day effect and a gradual effect for easter does not make economic sense for the aggregated series. The specification that should be used with X-13ARIMA is
spec = RJDemetra::x13_spec("RSA3", tradingdays.option = "WorkingDays"). If no new data or seasonal adjustment specification is specified (method or specification), these parameters is inherited from the previous defined: therefore you only need to specify this parameter once.
geom_sa() adds the seasonal adjusted time series:
To add other components of the seasonal adjustment, use the
component parameter of
?RJDemetra::user_defined_variables() for the availables parameters). For example, to add the forecasts of the input data and of the seasonal adjusted series:
There are four differents geometrics to add to the plot the names of the outliers used in the pre-adjustment process:
geom = "text"(the default) adds directly the names of the outliers and
geom = "label"draws a rectangle behind the names, making them easier to read.
geom = "text_repel"and
geom = "label_repel"do the same but text labels repel away from each other and away from the data points (see
In our example, there are 3 outliers:
They can be plotted in more readable way using the parameters of
Use the parameters
last_date to only have the outliers in a precise time interval. For example, to only plot the outliers from 2009 use
first_date = 2009:
The ARIMA model used pre-adjustment process can be added to the plot with
geom_ arima(). The parameter
geom = "label" draws a rectangle behind the ARIMA model, making it easier to read:
A table with some diagnostics on the seasonal adjustment process can be added with
geom_diagnostics(). The desired diagnostics have to be added to the
diagnostics parameter (see
?RJDemetra::user_defined_variables() for the availables diagnostics). For example, to add the result of the X-11 combined test and the p-values of the residual seasonality qs and f tests:
To customize the names of the diagnostics in the plot, pass a named vector to the
diagnostics <- c(`Combined test` = "diagnostics.combined.all.summary", `Residual qs-test (p-value)` = "diagnostics.qs", `Residual f-test (p-value)` = "diagnostics.ftest") p_sa + geom_diagnostics(diagnostics = diagnostics, ymin = 58, ymax = 72, xmin = 2010, table_theme = gridExtra::ttheme_default(base_size = 8))
To add the table below the plot, you can for example use