| har_plot | R Documentation |
Convenience plotting helper for Harbinger detections. It accepts a detector, the input series, an optional detection data.frame, and optional ground-truth events to color-code true positives (TP), false positives (FP), and false negatives (FN). It can also mark detected change points and draw reference horizontal lines.
har_plot(
obj,
serie,
detection = NULL,
event = NULL,
mark.cp = TRUE,
ylim = NULL,
idx = NULL,
pointsize = 0.5,
colors = c("green", "blue", "red", "purple"),
yline = NULL
)
obj |
A |
serie |
Numeric vector with the time series to plot. |
detection |
Optional detection data.frame as returned by |
event |
Optional logical vector with ground-truth events (same length as |
mark.cp |
Logical; if TRUE, marks detected change points with dashed vertical lines. |
ylim |
Optional numeric vector of length 2 for y-axis limits. |
idx |
Optional x-axis labels or indices (defaults to |
pointsize |
Base point size for observations. |
colors |
Character vector of length 4 with colors for TP, FN, FP, and motif segments. |
yline |
Optional numeric vector with y values to draw dotted horizontal lines. |
A ggplot object showing the time series with detected events highlighted.
Ogasawara, E., Salles, R., Porto, F., Pacitti, E. Event Detection in Time Series. 1st ed. Cham: Springer Nature Switzerland, 2025. doi:10.1007/978-3-031-75941-3
library(daltoolbox)
# Load an example anomaly dataset
data(examples_anomalies)
# Use the simple time series
dataset <- examples_anomalies$simple
head(dataset)
# Set up an ARIMA-based anomaly detector
model <- hanr_arima()
# Fit the detector
model <- fit(model, dataset$serie)
# Run detection
detection <- detect(model, dataset$serie)
# Inspect detected events
print(detection[(detection$event),])
# Evaluate detections (soft evaluation)
evaluation <- evaluate(har_eval_soft(), detection$event, dataset$event)
print(evaluation$confMatrix)
# Plot the results
grf <- har_plot(model, dataset$serie, detection, dataset$event)
plot(grf)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.