set.seed(1)
df <- tibble(
time = seq(41),
y = c(rnorm(20), 5, rnorm(20))
) |>
mutate(hampel = hampel_anomalies(y, bandwidth = 3, k = 4))
df |> ggplot(aes(x = time, y = y)) +
geom_line() +
geom_point(data = df |> filter(hampel), col = "red")
Run the code above in your browser using DataLab