| stat_changepoint | R Documentation |
Runs changepoint detection inside the ggplot pipeline. Useful for
quick exploration: ggplot(df, aes(t, y)) + geom_line() +
stat_changepoint(method = "pelt"). Draws vertical lines at detected
changepoint locations.
stat_changepoint(
mapping = NULL,
data = NULL,
geom = "vline",
position = "identity",
...,
method = "pelt",
change_in = "mean",
na.rm = FALSE,
show.legend = NA
)
mapping |
Aesthetic mappings. |
data |
A data frame. |
geom |
The geometric object to use (default: |
position |
Position adjustment. |
... |
Other arguments passed to the geom. |
method |
Detection method (passed to |
change_in |
What to detect change in (passed to |
na.rm |
If |
show.legend |
Whether to show legend. |
A ggplot layer.
Other ggplot2 layers:
geom_changepoint(),
geom_cpt_ci(),
geom_cpt_event(),
geom_cpt_label(),
geom_cpt_region(),
geom_cpt_segment(),
ggchangepoint-ggproto,
stat_cpt_region()
library(ggplot2)
set.seed(2026)
d <- data.frame(t = 1:100, y = c(rnorm(50), rnorm(50, 4)))
ggplot(d, aes(t, y)) + geom_line() +
stat_changepoint(method = "pelt", colour = "blue")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.