Skip to contents

Renders a changepoint detection result as a ggplot. The raw series is drawn as a line (with optional points), changepoints are shown as vertical lines, and (optionally) fitted segment levels, the engine's fitted signal, and changepoint-location confidence intervals are overlaid. Multivariate results (from ecp, inspect, geomcp, ...) are drawn as faceted small-multiples with shared changepoint rules.

Usage

# S3 method for class 'ggcpt'
autoplot(
  object,
  show_segments = FALSE,
  show_ci = FALSE,
  show_fit = FALSE,
  show_regions = NULL,
  cptline_alpha = 1,
  cptline_color = "blue",
  cptline_type = "solid",
  cptline_linewidth = 0.5,
  show_points = NULL,
  show_line = TRUE,
  index = NULL,
  labels = NULL,
  type = c("series", "statistic", "path", "scale_space"),
  ...
)

Arguments

object

A ggcpt object.

show_segments

Logical. Whether to draw the fitted segment means. Defaults to FALSE.

show_ci

Logical. Whether to draw confidence intervals for changepoint locations, when the engine provides them (columns ci_lower/ci_upper on the changepoints tibble, supplied by the engines cpt_methods() marks in its ci column: smuce, hsmuce, strucchange, segmented, mcp, bfast and taylor). nsp is marked there as well but is not drawn by this argument: it reports region_start/region_end rather than an interval around an estimate, which show_regions draws. Drawn as horizontal whiskers near the bottom of the panel. Defaults to FALSE.

show_fit

Logical. Whether to draw the engine's fitted signal (the fitted column of $data, provided by the engines cpt_methods() marks in its fitted column: smuce, hsmuce, cpop, bcp, beast, decafs, segmented, mcp and bfast). Defaults to FALSE.

show_regions

Logical. Whether to shade the significance regions an interval-valued method returns (the regions slot; currently nsp_wrapper()). Each band is an interval that contains at least one changepoint at the stated global level; it is not a confidence interval around a point estimate. Defaults to TRUE when the result carries regions, and is ignored otherwise.

cptline_alpha

Alpha for changepoint lines. Defaults to 1.

cptline_color

Color for changepoint lines. Defaults to "blue".

cptline_type

Linetype for changepoint lines. Defaults to "solid".

cptline_linewidth

Linewidth for changepoint lines. Defaults to 0.5.

show_points

Logical. Whether to draw data points. Auto-off above 500 obs.

show_line

Logical. Whether to draw the line. Defaults to TRUE.

index

Optional vector of x-axis values (e.g. dates) of the same length as the series. Defaults to the time index carried by the result (see the index argument of cpt_detect()), and to the observation position when there is none.

labels

Optional cpt_labels() tibble. When supplied, the labelled regions are shaded behind the series and coloured by the outcome cpt_label_error() gives them (correct, false positive, false negative), so scoring a segmentation against expert labels becomes a picture rather than a table. Not drawn for a multivariate result, which warns instead.

type

Which view to draw. "series" (default) is the series with its changepoints; "statistic" and "path" delegate to ggcpt_statistic() and ggcpt_solution_path(), which error with the list of supporting engines when this one does not expose the internals. "scale_space" delegates to ggcpt_scale_space(), which needs nothing from the engine: it sweeps a multiscale detector over the same series, so it draws for any result.

...

Unknown arguments are ignored with a warning, except when type is not "series", in which case they are passed to the delegate.

Value

A ggplot object.

See also

ggcpt_plot_methods for the base plot() methods that delegate here, and theme_ggcpt() and geom_changepoint() for restyling and re-assembling the layers by hand.