Title: | 'ggplot2' Extension for Seasonal and Trading Day Adjustment with 'JDemetra+' 3.0 |
---|---|
Description: | Provides 'ggplot2' functions to return the results of seasonal and trading day adjustment made by the R interface to 'JDemetra+' 3.0. |
Authors: | Alain Quartier-la-Tente [aut, cre] |
Maintainer: | Alain Quartier-la-Tente <[email protected]> |
License: | EUPL |
Version: | 0.0.2 |
Built: | 2024-10-30 02:44:57 UTC |
Source: | https://github.com/AQLT/ggdemetra3 |
Plot 'rjdemetra3' model
## S3 method for class 'JD3_X13_OUTPUT' autoplot( object, components = c("y", "sa", trend = "t", seasonal = "s", irregular = "i"), forecast = FALSE, ... )
## S3 method for class 'JD3_X13_OUTPUT' autoplot( object, components = c("y", "sa", trend = "t", seasonal = "s", irregular = "i"), forecast = FALSE, ... )
object |
a seasonal adjustment model. |
components |
components to print, can be |
forecast |
boolean indicating if the forecast series should be printed. |
... |
unused arguments. |
x = rjd3x13::x13(ipi_c_eu[,"FR"]) ggplot2::autoplot(x)
x = rjd3x13::x13(ipi_c_eu[,"FR"]) ggplot2::autoplot(x)
Extract Component from 'RJDemetra' model
seasonal(x, forecast = FALSE, calendar = FALSE, ...) trendcycle(x, forecast = FALSE, ...) irregular(x, forecast = FALSE, corrected = FALSE, ...) seasonaladj(x, forecast = FALSE, corrected = FALSE, ...) calendaradj(x, forecast = FALSE, ...) calendar(x, forecast = FALSE, ...) raw(x, forecast = FALSE, backcast = FALSE, ...)
seasonal(x, forecast = FALSE, calendar = FALSE, ...) trendcycle(x, forecast = FALSE, ...) irregular(x, forecast = FALSE, corrected = FALSE, ...) seasonaladj(x, forecast = FALSE, corrected = FALSE, ...) calendaradj(x, forecast = FALSE, ...) calendar(x, forecast = FALSE, ...) raw(x, forecast = FALSE, backcast = FALSE, ...)
x |
a seasonal adjustment object. |
forecast , backcast
|
boolean indicating if the forecast/backcast series should be returned. |
calendar |
if |
... |
unused parameters. |
corrected |
if |
Function to add directly to the plot the ARIMA model used in the pre-adjustment process of the seasonal adjustment.
geom_arima( mapping = NULL, data = NULL, stat = "arima", geom = c("text", "label"), position = "identity", ..., method = c("x13", "tramoseats"), spec = NULL, frequency = NULL, message = TRUE, x_arima = NULL, y_arima = NULL, show.legend = NA, inherit.aes = TRUE )
geom_arima( mapping = NULL, data = NULL, stat = "arima", geom = c("text", "label"), position = "identity", ..., method = c("x13", "tramoseats"), spec = NULL, frequency = NULL, message = TRUE, x_arima = NULL, y_arima = NULL, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by aes() or
aes_(). If specified and |
data |
A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
geom |
character. The geometric to use to display the data:
|
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to layer(). These are
often aesthetics, used to set an aesthetic to a fixed value, like
|
method |
the method used for the seasonal adjustment. |
spec |
the specification used for the seasonal adjustment.
See |
frequency |
the frequency of the time series. By default ( |
message |
a |
x_arima , y_arima
|
position of the text of the ARIMA model. By default, the first position of the |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
With the parameter geom = "text"
, the ARIMA model used in the pre-adjustment process of the seasonal adjustment are directly added to the plot. With geom = "label"
a rectangle is drawn behind the ARIMA model, making it easier to read.
p_sa_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) + geom_sa(color = "red", message = FALSE) # To add the ARIMA model p_sa_ipi_fr + geom_arima(geom = "label", x_arima = - Inf, y_arima = -Inf, vjust = -1, hjust = -0.1, message = FALSE)
p_sa_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) + geom_sa(color = "red", message = FALSE) # To add the ARIMA model p_sa_ipi_fr + geom_arima(geom = "label", x_arima = - Inf, y_arima = -Inf, vjust = -1, hjust = -0.1, message = FALSE)
Adds a table of diagnostics to the plot
geom_diagnostics( mapping = NULL, data = NULL, position = "identity", ..., method = c("x13", "tramoseats"), spec = NULL, frequency = NULL, message = TRUE, diagnostics = NULL, digits = 2, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, table_theme = ttheme_default(), inherit.aes = TRUE )
geom_diagnostics( mapping = NULL, data = NULL, position = "identity", ..., method = c("x13", "tramoseats"), spec = NULL, frequency = NULL, message = TRUE, diagnostics = NULL, digits = 2, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, table_theme = ttheme_default(), inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by aes() or
aes_(). If specified and |
data |
A |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to layer(). These are
often aesthetics, used to set an aesthetic to a fixed value, like
|
method |
the method used for the seasonal adjustment. |
spec |
the specification used for the seasonal adjustment.
See |
frequency |
the frequency of the time series. By default ( |
message |
a |
diagnostics |
vector of character containing the name of the diagnostics to plot.
See |
digits |
integer indicating the number of decimal places to be used for numeric diagnostics. By default |
xmin , xmax
|
x location (in data coordinates) giving horizontal location of raster. |
ymin , ymax
|
y location (in data coordinates) giving vertical location of raster. |
table_theme |
list of theme parameters for the table of diagnostics (see ttheme_default()). |
inherit.aes |
If |
p_sa_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) + geom_sa(color = "red", message = FALSE) # To add of diagnostics with result of the X-11 combined test and the p-values # of the residual seasonality qs and f tests: diagnostics <- c("diagnostics.seas-sa-combined", "diagnostics.seas-sa-qs", "diagnostics.seas-sa-f") p_sa_ipi_fr + geom_diagnostics(diagnostics = diagnostics, ymin = 58, ymax = 72, xmin = 2010, table_theme = gridExtra::ttheme_default(base_size = 8), message = FALSE) # To customize the names of the diagnostics in the plot: diagnostics <- c(`Combined test` = "diagnostics.seas-sa-combined", `Residual qs-test (p-value)` = "diagnostics.seas-sa-qs", `Residual f-test (p-value)` = "diagnostics.seas-sa-f") p_sa_ipi_fr + geom_diagnostics(diagnostics = diagnostics, ymin = 58, ymax = 72, xmin = 2010, table_theme = gridExtra::ttheme_default(base_size = 8), message = FALSE) # To add the table below the plot: p_diag <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_diagnostics(diagnostics = diagnostics, table_theme = gridExtra::ttheme_default(base_size = 8), message = FALSE) + theme_void() gridExtra::grid.arrange(p_sa_ipi_fr, p_diag, nrow = 2, heights = c(4, 1))
p_sa_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) + geom_sa(color = "red", message = FALSE) # To add of diagnostics with result of the X-11 combined test and the p-values # of the residual seasonality qs and f tests: diagnostics <- c("diagnostics.seas-sa-combined", "diagnostics.seas-sa-qs", "diagnostics.seas-sa-f") p_sa_ipi_fr + geom_diagnostics(diagnostics = diagnostics, ymin = 58, ymax = 72, xmin = 2010, table_theme = gridExtra::ttheme_default(base_size = 8), message = FALSE) # To customize the names of the diagnostics in the plot: diagnostics <- c(`Combined test` = "diagnostics.seas-sa-combined", `Residual qs-test (p-value)` = "diagnostics.seas-sa-qs", `Residual f-test (p-value)` = "diagnostics.seas-sa-f") p_sa_ipi_fr + geom_diagnostics(diagnostics = diagnostics, ymin = 58, ymax = 72, xmin = 2010, table_theme = gridExtra::ttheme_default(base_size = 8), message = FALSE) # To add the table below the plot: p_diag <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_diagnostics(diagnostics = diagnostics, table_theme = gridExtra::ttheme_default(base_size = 8), message = FALSE) + theme_void() gridExtra::grid.arrange(p_sa_ipi_fr, p_diag, nrow = 2, heights = c(4, 1))
Function to add directly to the plot the outliers used in the pre-adjustment process of the seasonal adjustment.
geom_outlier( mapping = NULL, data = NULL, stat = "outlier", geom = c("text", "label", "text_repel", "label_repel"), position = "identity", ..., method = c("x13", "tramoseats"), spec = NULL, frequency = NULL, message = TRUE, first_date = NULL, last_date = NULL, coefficients = FALSE, digits = 1, show.legend = NA, inherit.aes = TRUE )
geom_outlier( mapping = NULL, data = NULL, stat = "outlier", geom = c("text", "label", "text_repel", "label_repel"), position = "identity", ..., method = c("x13", "tramoseats"), spec = NULL, frequency = NULL, message = TRUE, first_date = NULL, last_date = NULL, coefficients = FALSE, digits = 1, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by aes() or
aes_(). If specified and |
data |
A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
geom |
character. The geometric to use to display the data:
|
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to layer(). They may be parameters of
geom_text() (if |
method |
the method used for the seasonal adjustment. |
spec |
the specification used for the seasonal adjustment.
See |
frequency |
the frequency of the time series. By default ( |
message |
a |
first_date |
A numeric specifying the first date from which the outliers are plotted.
By default ( |
last_date |
A numeric specifying the first date from which the outliers are plotted.
By default ( |
coefficients |
boolean indicating if the estimates coefficients are printed.
By default |
digits |
integer indicating the number of decimal places to be used for numeric diagnostics. By default |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
With the parameter geom = "text"
, the outliers used in the pre-adjustment process of the seasonal adjustment are directly added to the plot. With geom = "label"
a rectangle is drawn behind the names of the outliers, making them easier to read. The same with geom = "text_repel"
or geom = "label_repel"
but text labels are also repeled away from each other and away from the data points (see geom_label_repel()).
p_sa_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) + geom_sa(color = "red", message = FALSE) # To add the outliers: p_sa_ipi_fr + geom_outlier(geom = "label", message = FALSE) # To have a more readable plot with outliers names that repeled away from each other # and from the data points: p_sa_ipi_fr + geom_outlier(geom = "label_repel", message = FALSE, vjust = 4, ylim = c(NA, 65), force = 10, arrow = arrow(length = unit(0.03, "npc"), type = "closed", ends = "last")) # To only plot the outliers from a specific date (2009): p_sa_ipi_fr + geom_outlier(geom = "label_repel", message = FALSE, first_date = 2009, vjust = 4, ylim = c(NA, 65), force = 10, arrow = arrow(length = unit(0.03, "npc"), type = "closed", ends = "last"))
p_sa_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) + geom_sa(color = "red", message = FALSE) # To add the outliers: p_sa_ipi_fr + geom_outlier(geom = "label", message = FALSE) # To have a more readable plot with outliers names that repeled away from each other # and from the data points: p_sa_ipi_fr + geom_outlier(geom = "label_repel", message = FALSE, vjust = 4, ylim = c(NA, 65), force = 10, arrow = arrow(length = unit(0.03, "npc"), type = "closed", ends = "last")) # To only plot the outliers from a specific date (2009): p_sa_ipi_fr + geom_outlier(geom = "label_repel", message = FALSE, first_date = 2009, vjust = 4, ylim = c(NA, 65), force = 10, arrow = arrow(length = unit(0.03, "npc"), type = "closed", ends = "last"))
Performs a seasonal adjustment and plots a time seriesAids the eye in seeing patterns in the presence of overplotting. geom_sa()
and stat_sa()
are aliases: they both use the same arguments. Use stat_sa()
if you want to display the results with a non-standard geom.
geom_sa( mapping = NULL, data = NULL, stat = "sa", position = "identity", ..., method = c("x13", "tramoseats", "x11-extended", "fractionalairline", "fractionalairlineestimation", "multiairline"), spec = NULL, frequency = NULL, message = TRUE, component = "sa", show.legend = NA, inherit.aes = TRUE ) stat_sa( mapping = NULL, data = NULL, geom = "line", position = "identity", ..., method = c("x13", "tramoseats", "x11-extended", "fractionalairline", "fractionalairlineestimation", "multiairline"), spec = NULL, frequency = NULL, message = TRUE, component = "sa", show.legend = NA, inherit.aes = TRUE )
geom_sa( mapping = NULL, data = NULL, stat = "sa", position = "identity", ..., method = c("x13", "tramoseats", "x11-extended", "fractionalairline", "fractionalairlineestimation", "multiairline"), spec = NULL, frequency = NULL, message = TRUE, component = "sa", show.legend = NA, inherit.aes = TRUE ) stat_sa( mapping = NULL, data = NULL, geom = "line", position = "identity", ..., method = c("x13", "tramoseats", "x11-extended", "fractionalairline", "fractionalairlineestimation", "multiairline"), spec = NULL, frequency = NULL, message = TRUE, component = "sa", show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by aes() or
aes_(). If specified and |
data |
A |
stat |
The statistical transformation to use on the data for this layer, as a string. |
position |
Position adjustment, either as a string, or the result of a call to a position adjustment function. |
... |
Other arguments passed on to layer(). These are
often aesthetics, used to set an aesthetic to a fixed value, like
|
method |
the method used for the seasonal adjustment. |
spec |
the specification used for the seasonal adjustment.
See |
frequency |
the frequency of the time series. By default ( |
message |
a |
component |
a |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use to display the data |
p_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) # To add the seasonal adjusted series: p_ipi_fr + geom_sa(color = "red") # To add the forecasts of the input data and the seasonal adjusted series: p_sa <- p_ipi_fr + geom_sa(component = "y_f", linetype = 2, message = FALSE) + geom_sa(component = "sa", color = "red", message = FALSE) + geom_sa(component = "sa_f", color = "red", linetype = 2, message = FALSE) p_sa
p_ipi_fr <- ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) + geom_line() + labs(title = "Seasonal adjustment of the French industrial production index", x = "time", y = NULL) # To add the seasonal adjusted series: p_ipi_fr + geom_sa(color = "red") # To add the forecasts of the input data and the seasonal adjusted series: p_sa <- p_ipi_fr + geom_sa(component = "y_f", linetype = 2, message = FALSE) + geom_sa(component = "sa", color = "red", message = FALSE) + geom_sa(component = "sa_f", color = "red", linetype = 2, message = FALSE) p_sa
'ggplot2' functions for 'rjd3filters' plots
ggplot_coef(x, zero_as_na = TRUE, ylab = "Coefficients", ...) ## S3 method for class 'finite_filters' ggplot_coef(x, zero_as_na = TRUE, ylab = "Coefficients", q = 0, ...) ggplot_gain(x, nxlab = 7, xlim = c(0, pi), ..., n = 101) ggplot_phase(x, nxlab = 7, xlim = c(0, pi), normalized = FALSE, ..., n = 101)
ggplot_coef(x, zero_as_na = TRUE, ylab = "Coefficients", ...) ## S3 method for class 'finite_filters' ggplot_coef(x, zero_as_na = TRUE, ylab = "Coefficients", q = 0, ...) ggplot_gain(x, nxlab = 7, xlim = c(0, pi), ..., n = 101) ggplot_phase(x, nxlab = 7, xlim = c(0, pi), normalized = FALSE, ..., n = 101)
x , zero_as_na , q , ylab , nxlab , xlim , n , normalized , ...
|
see function rjd3filters::plot_coef. |
A dataset containing on monthly industrial production indices in manufacturing in the European Union (from sts_inpr_m dataset of Eurostat). Data are based 100 in 2015 and are unadjusted, i.e. neither seasonally adjusted nor calendar adjusted.
ipi_c_eu ipi_c_eu_df
ipi_c_eu ipi_c_eu_df
A monthly ts
object from january 1990 to december 2017 with 34 variables for ipi_c_eu
and a data.frame
for ipi_c_eu_df
.
An object of class data.frame
with 360 rows and 35 columns.
The dataset contains 34 time series corresponding to the following geographical area
BE | Belgium |
BG | Bulgaria |
CZ | Czechia |
DK | Denmark |
DE | Germany (until 1990 former territory of the FRG) |
EE | Estonia |
IE | Ireland |
EL | Greece |
ES | Spain |
FR | France |
HR | Croatia |
IT | Italy |
CY | Cyprus |
LV | Latvia |
LT | Lithuania |
LU | Luxembourg |
HU | Hungary |
MT | Malta |
NL | Netherlands |
AT | Austria |
PL | Poland |
PT | Portugal |
RO | Romania |
SI | Slovenia |
SK | Slovakia |
FI | Finland |
SE | Sweden |
UK | United Kingdom |
NO | Norway |
CH | Switzerland |
ME | Montenegro |
MK | Former Yugoslav Republic of Macedonia, the |
RS | Serbia |
TR | Turkey |
BA | Bosnia and Herzegovina |
SI-ratio
siratio(x, ...) siratioplot( x, labels = NULL, add = FALSE, box = TRUE, col.s = "darkblue", col.i = "gray", col.mean = "red", cex.i = 0.1, lwd.s = par("lwd"), lwd.mean = lwd.s, main = "SI ratio", xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, ... ) ggsiratioplot( x, labels = NULL, col.s = "darkblue", col.i = "gray", col.mean = "red", cex.i = 0.5, lwd.s = 1, lwd.mean = lwd.s, main = "SI ratio", xlab = NULL, ylab = NULL, ... )
siratio(x, ...) siratioplot( x, labels = NULL, add = FALSE, box = TRUE, col.s = "darkblue", col.i = "gray", col.mean = "red", cex.i = 0.1, lwd.s = par("lwd"), lwd.mean = lwd.s, main = "SI ratio", xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, ... ) ggsiratioplot( x, labels = NULL, col.s = "darkblue", col.i = "gray", col.mean = "red", cex.i = 0.5, lwd.s = 1, lwd.mean = lwd.s, main = "SI ratio", xlab = NULL, ylab = NULL, ... )
x |
input model or data. |
... |
unused parameters. |
labels |
labels. |
add |
boolean indicating whether a new plot should be drawn. |
box |
boolean indicating a box around the current plot should be drawn. |
col.s , col.i , col.mean
|
colors of the different components. |
cex.i , lwd.s , lwd.mean
|
graphical parameters. |
main , xlab , ylab
|
title, X and Y axis label. |
xlim , ylim
|
X and Y axis limits. |
x <- rjd3x13::x13(ipi_c_eu[,"FR"]) siratioplot(x) ggsiratioplot(x)
x <- rjd3x13::x13(ipi_c_eu[,"FR"]) siratioplot(x) ggsiratioplot(x)
Function to a ts
or mts
object to a data.frame
that can be directly used in the plot functions.
ts2df(x)
ts2df(x)
x |
a |
a data.frame
object.
# To get the ipi_c_eu_df object: ts2df(ipi_c_eu)
# To get the ipi_c_eu_df object: ts2df(ipi_c_eu)
Weekly US claims
usclaims
usclaims
An object of class data.frame
with 2868 rows and 3 columns.