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
)

Arguments

mapping

Set of aesthetic mappings created by aes() or aes_(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

A data.frame that contains the data used for the seasonal adjustment.

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 colour = "red" or size = 3.

method

the method used for the seasonal adjustment. "x13" (by default) for the X-13ARIMA method and "tramoseats" for TRAMO-SEATS.

spec

the specification used for the seasonal adjustment. See rjd3x13::x13() or rjd3tramoseats::tramoseats().

frequency

the frequency of the time series. By default (frequency = NULL), the frequency is computed automatically.

message

a boolean indicating if a message is printed with the frequency used.

diagnostics

vector of character containing the name of the diagnostics to plot. See rjd3x13::userdefined_variables_x13() or rjd3tramoseats::userdefined_variables_tramoseats() for the available parameters.

digits

integer indicating the number of decimal places to be used for numeric diagnostics. By default digits = 2.

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 FALSE, overrides the default aesthetics, rather than combining with them.

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 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)
#> Warning: The following aesthetics were dropped during statistical transformation: x and
#> y.
#>  This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#>  Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?


# 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)
#> Warning: The following aesthetics were dropped during statistical transformation: x and
#> y.
#>  This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#>  Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?


# 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))
#> Warning: The following aesthetics were dropped during statistical transformation: x and
#> y.
#>  This can happen when ggplot fails to infer the correct grouping structure in
#>   the data.
#>  Did you forget to specify a `group` aesthetic or to convert a numerical
#>   variable into a factor?