#' Plot change point detection results
#'
#' @param ts Time series input
#' @param step Starting point of detection
#' @param scores rPE scores
#' @param change_points Detected change point indices
#'
ts_plot <- function(ts, step, scores, change_points) {
# dimension parameters
ts_dim <- dim(ts)[1]
n_time_points <- dim(ts)[2]
# graphical parameters
graphics::par(mfrow = c(ts_dim + 1, 1),
oma = rep(1, 4),
mar = rep(1.2, 4))
# plot each time series
for (s in 1:ts_dim) {
# plot the time series
plot(1:n_time_points, ts[s, ], type = 'l',
xlab = NULL, ylab = paste("y", s, sep = ''),
xlim = c(1, n_time_points),
ylim = c(min(ts[s, ]), max(ts[s, ])))
# plot rectangles to highlight change points
graphics::rect(xleft = change_points,
ybottom = rep(min(ts[s, ]), length(change_points)),
xright = change_points + 1,
ytop = rep(max(ts[s, ]), length(change_points)),
col = '#DD666666', border = NA)
}
# plot scores
plot(1:length(scores) + step, scores,
type = 'l',
xlab = 'time', ylab = 'rPE',
xlim = c(1, n_time_points),
col = 'red')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.