Skip to contents

Convenience S3 methods for working with ggcpt objects: coerce the changepoints to a tibble or data frame, render a one-line summary string, or produce the default plot (a base-graphics fallback that delegates to autoplot.ggcpt).

Usage

# S3 method for class 'ggcpt'
as_tibble(x, ..., .name_repair = NULL)

# S3 method for class 'ggcpt'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

# S3 method for class 'ggcpt'
format(x, ...)

# S3 method for class 'ggcpt'
plot(x, ...)

Arguments

x

A ggcpt object.

...

Additional arguments passed to methods.

.name_repair

Ignored (the changepoints tibble already has valid, unique names); present for signature compatibility with the generic.

row.names, optional

Passed to as.data.frame.

Value

as_tibble() and as.data.frame() return the changepoints table; format() returns a length-one character string; plot() returns a ggplot object.

Examples

set.seed(2022)
res <- cpt_detect(c(rnorm(50), rnorm(50, 5)), method = "pelt")
as_tibble(res)
#> # A tibble: 1 × 2
#>      cp cp_value
#>   <int>    <dbl>
#> 1    50    0.368
as.data.frame(res)
#>   cp  cp_value
#> 1 50 0.3681734
format(res)
#> [1] "ggcpt [pelt] 1 changepoint(s) on 100 observations"