mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-09-16 22:20:23 +00:00
Add layer_changepoints from #273
This commit is contained in:
parent
c6b76aab8c
commit
c3d2280af8
3 changed files with 69 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ export(add_regressor)
|
||||||
export(add_seasonality)
|
export(add_seasonality)
|
||||||
export(cross_validation)
|
export(cross_validation)
|
||||||
export(fit.prophet)
|
export(fit.prophet)
|
||||||
|
export(layer_changepoints)
|
||||||
export(make_future_dataframe)
|
export(make_future_dataframe)
|
||||||
export(plot_forecast_component)
|
export(plot_forecast_component)
|
||||||
export(predictive_samples)
|
export(predictive_samples)
|
||||||
|
|
|
||||||
33
R/R/utils.R
Normal file
33
R/R/utils.R
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#' Get layers to overlay significant changepoints on prophet forecast plot.
|
||||||
|
#'
|
||||||
|
#' @param m Prophet model object.
|
||||||
|
#' @param threshold Numeric, changepoints where abs(delta) >= threshold are
|
||||||
|
#' significant. (Default 0.01)
|
||||||
|
#' @param cp_color Character, line color. (Default "red")
|
||||||
|
#' @param cp_linetype Character or integer, line type. (Default "dashed")
|
||||||
|
#' @param trend Logical, if FALSE, do not draw trend line. (Default TRUE)
|
||||||
|
#' @param ... Other arguments passed on to layers.
|
||||||
|
#'
|
||||||
|
#' @return A list of ggplot2 layers.
|
||||||
|
#'
|
||||||
|
#' @examples
|
||||||
|
#' \dontrun{
|
||||||
|
#' plot(m, fcst) + layer_changepoints(m)
|
||||||
|
#' }
|
||||||
|
#'
|
||||||
|
#' @export
|
||||||
|
layer_changepoints <- function(m, threshold = 0.01, cp_color = "red",
|
||||||
|
cp_linetype = "dashed", trend = TRUE, ...) {
|
||||||
|
layers <- list()
|
||||||
|
if (trend) {
|
||||||
|
trend_layer <- ggplot2::geom_line(
|
||||||
|
ggplot2::aes_string("ds", "trend"), color = cp_color, ...)
|
||||||
|
layers <- append(layers, trend_layer)
|
||||||
|
}
|
||||||
|
signif_changepoints <- m$changepoints[abs(m$params$delta) >= threshold]
|
||||||
|
cp_layer <- ggplot2::geom_vline(
|
||||||
|
xintercept = as.integer(signif_changepoints), color = cp_color,
|
||||||
|
linetype = cp_linetype, ...)
|
||||||
|
layers <- append(layers, cp_layer)
|
||||||
|
return(layers)
|
||||||
|
}
|
||||||
35
R/man/layer_changepoints.Rd
Normal file
35
R/man/layer_changepoints.Rd
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/utils.R
|
||||||
|
\name{layer_changepoints}
|
||||||
|
\alias{layer_changepoints}
|
||||||
|
\title{Get layers to overlay significant changepoints on prophet forecast plot.}
|
||||||
|
\usage{
|
||||||
|
layer_changepoints(m, threshold = 0.01, cp_color = "red",
|
||||||
|
cp_linetype = "dashed", trend = TRUE, ...)
|
||||||
|
}
|
||||||
|
\arguments{
|
||||||
|
\item{m}{Prophet model object.}
|
||||||
|
|
||||||
|
\item{threshold}{Numeric, changepoints where abs(delta) >= threshold are
|
||||||
|
significant. (Default 0.01)}
|
||||||
|
|
||||||
|
\item{cp_color}{Character, line color. (Default "red")}
|
||||||
|
|
||||||
|
\item{cp_linetype}{Character or integer, line type. (Default "dashed")}
|
||||||
|
|
||||||
|
\item{trend}{Logical, if FALSE, do not draw trend line. (Default TRUE)}
|
||||||
|
|
||||||
|
\item{...}{Other arguments passed on to layers.}
|
||||||
|
}
|
||||||
|
\value{
|
||||||
|
A list of ggplot2 layers.
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
Get layers to overlay significant changepoints on prophet forecast plot.
|
||||||
|
}
|
||||||
|
\examples{
|
||||||
|
\dontrun{
|
||||||
|
plot(m, fcst) + layer_changepoints(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue