Skip to contents

Draws horizontal segments representing the estimated level of each segment between changepoints. Typically used with data from augment().

Usage

geom_cpt_segment(
  mapping = NULL,
  data = NULL,
  ...,
  na.rm = FALSE,
  show.legend = NA
)

Arguments

mapping

Aesthetic mappings. Requires x, xend, y, yend.

data

A data frame with segment information.

...

Other arguments passed to geom_segment.

na.rm

If FALSE, missing values are removed.

show.legend

Whether to show legend.

Value

A ggplot layer.

Examples

library(ggplot2)
set.seed(2026)
fit <- cpt_detect(c(rnorm(50), rnorm(50, 4)), method = "pelt")
ggplot(fit$data, aes(index, value)) + geom_line(colour = "grey70") +
  geom_cpt_segment(aes(x = start, xend = end, y = param_estimate,
                       yend = param_estimate),
                   data = fit$segments, colour = "blue", linewidth = 1)