Function to directly add the outliers used in the pre-adjustment process of the seasonal adjustment to the plot.
Only available for X-13 (rjd3x13::x13()) and TRAMO-SEATS (rjd3tramoseats::tramoseats()) methods.
Usage
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
)Arguments
- mapping
Set of aesthetic mappings created by
ggplot2::aes(). If specified andinherit.aes = TRUE(the default), it is combined with the default mapping at the top level of the plot. You must supplymappingif there is no plot mapping.- data
A
data.framethat contains the data used for the seasonal adjustment.- stat
The statistical transformation to use on the data for this layer, as a string.
- geom
Character. The geometry to use to display the data:
GeomText(geom = "text", seeggplot2::geom_text());GeomLabel(geom = "label", seeggplot2::geom_label());GeomTextRepel(geom = "text_repel", the default, seeggrepel::geom_text_repel());GeomLabelRepel(geom = "label_repel", seeggrepel::geom_label_repel()).- position
Position adjustment, either as a string, or the result of a call to a position adjustment function.
- ...
Other arguments passed on to
ggplot2::layer(). They may be parameters ofggplot2::geom_text()(ifgeom = "text"),ggplot2::geom_label()(ifgeom = "label"),ggrepel::geom_text_repel()(ifgeom = "text_repel") orggrepel::geom_label_repel()(ifgeom = "label_repel").- method
The method used for the seasonal adjustment.
"x13"(by default) for the X-13 method (usingrjd3x13::jx13()) and"tramoseats"for TRAMO-SEATS (usingrjd3tramoseats::.jtramoseats()). Both methods are only compatible with series of frequency 12 (monthly), 6 (bimonthly), 4 (quarterly), and 2 (semi-annual). For other frequencies, the following methods are available:"x11-extended"(seerjd3highfreq::x11plus()),"fractionalairline"(seerjd3highfreq::fractional_airline_decomposition()),"multiairline"(seerjd3highfreq::multi_airline_decomposition()),"stl"(seerjd3highfreq::stlplus()),"istl"(seerjd3highfreq::istl()), and"mstl"(seerjd3highfreq::mstl()).- spec
The specification used for the seasonal adjustment. For
"x13"and"tramoseats"methods, it can be the name of a pre-defined specification or a user-defined specification created withrjd3x13::spec_x13()orrjd3tramoseats::spec_tramoseats(). For other methods, it can be a list of parameters used in the associated seasonal adjustment function.- frequency
The frequency of the time series. By default (
frequency = NULL), the frequency is computed automatically.- message
A logical value indicating whether a message is printed with the frequency used.
- first_date
A numeric specifying the first date from which the outliers are plotted. By default (
first_date = NULL), the outliers are plotted from the beginning of the time series.- last_date
A numeric specifying the last date up to which the outliers are plotted. By default (
last_date = NULL), the outliers are plotted until the end of the time series.- coefficients
Logical indicating whether the estimated coefficients are printed. By default
coefficients = FALSE.- digits
Integer indicating the number of decimal places to be used for the estimated coefficients of the outliers. By default
digits = 1.- show.legend
Logical. Should this layer be included in the legends?
NA, the default, includes it if any aesthetics are mapped.FALSEnever includes it, andTRUEalways includes it. It can also be a named logical vector to finely select the aesthetics to display.- inherit.aes
If
FALSE, overrides the default aesthetics, rather than combining with them.
Details
With 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 applies to geom = "text_repel" or geom = "label_repel", but text labels are also repelled away from each other and away from the data points (see ggrepel::geom_label_repel()).
Examples
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 outlier names repelled 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"
)
)