## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = FALSE, comment = "",
                      fig.width = 7, fig.height = 4, dpi = 96,
                      dev.args = list(bg = "transparent"))
# Console colour carries no meaning on a rendered page. pkgdown turns it on for
# its own build, and the escape sequences then reach the reader as literal text,
# so colour is switched off here for a plain vignette render and a site build
# alike. The fixed width keeps printed output inside the documentation column.
options(cli.num_colors = 1, cli.hyperlink = FALSE, crayon.enabled = FALSE,
        width = 80)

# Figures on the package website sit on a warm off-white page in light mode and
# are inverted by pkgdown in dark mode, so an opaque background would read as a
# pale slab one way and a black plate the other. Two things paint one. The
# device
# canvas is made transparent by `dev.args` above, and theme_depictr() then
# inherits theme_minimal()'s white plot.background, which is drawn over that
# canvas, so it is cleared as each figure is printed. This is deliberately a
# vignette-level choice: theme_depictr() keeps its opaque background, which is
# what a figure saved for a paper wants.
transparent_bg <- ggplot2::theme(
  plot.background  = ggplot2::element_rect(fill = NA, colour = NA),
  panel.background = ggplot2::element_rect(fill = NA, colour = NA)
)
knit_print.ggplot <- function(x, ...) knitr::normal_print(x + transparent_bg)
knit_print.patchwork <- function(x, ...) knitr::normal_print(x & transparent_bg)

library(depictr)

## -----------------------------------------------------------------------------
timeseries_plot(monthly_sales, time = date, value = sales, group = series,
                rolling = 12, title = "Monthly sales by product line",
                y_lab = "Units")

## -----------------------------------------------------------------------------
indoor <- subset(monthly_sales, series == "indoor")
indoor <- indoor[order(indoor$date), ]
indoor_ts <- ts(indoor$sales, start = c(2018, 1), frequency = 12)

## ----fig.height = 6-----------------------------------------------------------
decompose_plot(indoor_ts, confidence = TRUE, title = "Indoor sales, decomposed")

## ----fig.height = 6-----------------------------------------------------------
decompose_plot(indoor_ts, method = "classical",
               title = "Indoor sales, classical decomposition")

## ----fig.height = 3.4---------------------------------------------------------
acf_plot(indoor_ts)

## ----fig.height = 3.4---------------------------------------------------------
acf_plot(indoor_ts, type = "partial")

## ----fig.height = 3.8---------------------------------------------------------
seasonal_plot(indoor_ts, title = "Indoor sales: monthly subseries")

## ----fig.height = 4-----------------------------------------------------------
seasonal_plot(indoor_ts, style = "season",
              title = "Indoor sales: one line per year")

## -----------------------------------------------------------------------------
fc <- ts_forecast(indoor_ts, h = 18, level = 0.9)
head(fc)

## ----fig.height = 4-----------------------------------------------------------
timeseries_plot(indoor_ts, forecast = 18, level = 0.9,
                title = "Indoor sales with an 18-month forecast",
                y_lab = "Units")

