plotly_ts.data.listR Documentation

Time series plotting

Description

Plot time series of observations and forecasts (lagged to be aligned in time).

Plot forecasts, residuals, cumulated residuals and RLS coefficients

Simply the same as plot_ts() with usely=TRUE, such that plotly is used.

Usage

## S3 method for class 'data.list'
plotly_ts(
  object,
  patterns = ".*",
  xlim = NA,
  ylims = NA,
  xlab = "",
  ylabs = NA,
  mains = "",
  mainouter = "",
  legendtexts = NA,
  colormaps = NA,
  xat = NA,
  usely = TRUE,
  p = NA,
  kseq = NA,
  ...
)

Arguments

object

A data.list or data.frame with observations and forecasts, note diffe

patterns

See plot_ts. The default pattern finds the generated series in the function, '!!RLSinputs!!' will be replaced with the names of the RLS inputs (regression stage inputs).

xlim

The time range as a character of length 2 and form "YYYY-MM-DD" or POSIX. Date to start and end the plot.

ylims

The ylim for each plot given in a list.

xlab

A character with the label for the x-axis.

ylabs

A character vector with labels for the y-axes.

mains

A character vector with the main for each plot.

mainouter

A character with the main at the top of the plot (can also be added afterwards with title(main, outer=TRUE)).

legendtexts

A list with the legend texts for each plot (replaces the names of the variables).

colormaps

A list of colormaps, which will be used in each plot.

xat

POSIXt specifying where the ticks on x-axis should be put.

usely

If TRUE then plotly will be used.

p

The plot_ts parameters in a list, as generated with the function par_ts().

kseq

For class(object)=="data.list" an integer vector, default = NA. Control which forecast horizons to include in the plots. If NA all the horizons will be included.

...

Parameters passed to par_ts, see the list of parameters in ?par_ts.

Details

Generates time series plots depending on the variables matched by each regular expression given in the patterns argument.

The forecasts matrices in the data.list given in object will be lagged to be aligned in time (i.e. k-step forecasts will be lagged by k).

Use the plotly package if argument usely is TRUE, see plotly_ts().

A useful plot for residual analysis and model validation of an RLS fitted forecast model.

All parameters, except those described below, are simply passed to plot_ts().

The plotly package must be installed and loaded.

Note that the plot parameters set with par_ts() have no effect on the plotly plots.

See https://onlineforecasting.org/vignettes/nice-tricks.html.

Value

A list with a data.frame with the data for each plot, if usely=TRUE, then a list of the figures (drawn with print(subplot(L, shareX=TRUE, nrows=length(L), titleY = TRUE))).

The plotted data in a data.list.

See Also

par_ts for setting plot control parameters.

regex for regular expressions to select which variables to plot.

plot_ts.

Examples


# Time series plots for \code{data.list}, same as for \code{data.frame} except use of \code{kseq}
D <- Dbuilding
plot_ts(D, c("heatload","Ta"), kseq=c(1,24))
# Make two plots (and set the space for the legend)
plot_ts(D, c("heatload","Ta"), kseq=c(1,24), legendspace=11)
# Only the Ta observations 
plot_ts(D, c("heatload","Taobs$"), kseq=c(1,24), legendspace=11)

# Give labels
plot_ts(D, c("heatload","Ta"), kseq=c(1,24), xlab="Time", ylabs=c("Heat (kW)","Temperature (C)"))
# Mains (see mainsline in par_ts())
plot_ts(D, c("heatload","Ta"), kseq=c(1,24), mains=c("Heatload","Temperature"), mainsline=c(-1,-2))

# Format of the xaxis (see par_ts())
plot_ts(D, c("heatload","Ta"), kseq=c(1,24), xaxisformat="%Y-%m-%d %H:%m")

# Return the data, for other plots etc.
L <- plot_ts(D, c("heatload","Ta"), kseq=c(1,24))
names(L[[1]])
names(L[[2]])



# Fit a model (see vignette 'setup-and-use-model'
D <- Dbuilding
D$scoreperiod <- in_range("2010-12-22", D$t)
model <- forecastmodel$new()
model$output = "heatload"
model$add_inputs(Ta = "Ta",
                 mu = "one()")
model$add_regprm("rls_prm(lambda=0.9)")
model$kseq <- c(3,18)
fit1 <- rls_fit(NA, model, D, returnanalysis = TRUE)

# Plot it
plot_ts(fit1)

# Return the data
Dplot <- plot_ts(fit1)

# The RLS coefficients are now in a nice format
head(Dplot$mu)


# See the website link above