| annotate_segments | R Documentation |
Adds alternating shaded rectangles to highlight segments between changepoints.
annotate_segments(cp, n, fill = c("grey90", "white"), alpha = 0.5, ...)
cp |
Changepoint indices (including 0 and n). |
n |
Length of the series. |
fill |
Colors for alternating segments. Defaults to c("grey90", "white"). |
alpha |
Alpha for fill. Defaults to 0.5. |
... |
Additional arguments passed to |
A list of ggplot annotations.
Other result class:
as_cpt_series(),
as_ggcpt(),
as_json(),
cpt_annotations(),
cpt_export(),
cpt_verify(),
ggchangepoint-conditions,
is_ggcpt(),
new_ggcpt(),
print.ggcpt()
library(ggplot2)
set.seed(2026)
fit <- cpt_detect(c(rnorm(50), rnorm(50, 4)), method = "pelt")
ggplot(fit$data, aes(index, value)) +
annotate_segments(fit$changepoints$cp, n = nrow(fit$data)) +
geom_line()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.