Learn R Programming

surveillance (version 1.23.1)

fanplot: Fan Plot of Forecast Distributions

Description

The fanplot() function in surveillance wraps functionality of the dedicated fanplot package, employing a different default style and optionally adding point predictions and observed values.

Usage

fanplot(quantiles, probs, means = NULL, observed = NULL, start = 1,
        fan.args = list(), means.args = list(), observed.args = list(),
        key.args = NULL, xlim = NULL, ylim = NULL, log = "",
        xlab = "Time", ylab = "No. infected", add = FALSE, ...)

Value

NULL (invisibly), with the side effect of drawing a fan chart.

Arguments

quantiles

a time x probs matrix of forecast quantiles at each time point.

probs

numeric vector of probabilities with values between 0 and 1.

means

(optional) numeric vector of point forecasts.

observed

(optional) numeric vector of observed values.

start

time index (x-coordinate) of the first prediction.

fan.args

a list of graphical parameters for the fan, e.g., to employ a different colorRampPalette as fan.col, or to enable contour lines via ln.

means.args

a list of graphical parameters for lines to modify the plotting style of the means. The default is a white line within the fan.

observed.args

a list of graphical parameters for lines to modify the plotting style of the observed values.

key.args

if a list, a color key (in fan()'s "boxfan"-style) is added to the fan chart. The list may include positioning parameters start (the x-position) and ylim (the y-range of the color key), space to modify the width of the boxfan, and rlab to modify the labels. An alternative way of labeling the quantiles is via the argument ln in fan.args.

xlim,ylim

axis ranges.

log

a character string specifying which axes are to be logarithmic, e.g., log="y" (see plot.default).

xlab,ylab

axis labels.

add

logical indicating if the fan plot should be added to an existing plot.

...

further arguments are passed to plot.default. For instance, panel.first could be used to initialize the plot with grid(nx=NA, ny=NULL) lines.

Author

Sebastian Meyer

See Also

the underlying fan function in package fanplot. The function is used in plot.oneStepAhead and plot.hhh4sims.

Examples

Run this code
## artificial data example to illustrate the graphical options
if (requireNamespace("fanplot")) {
    means <- c(18, 19, 20, 25, 26, 35, 34, 25, 19)
    y <- rlnorm(length(means), log(means), 0.5)
    quantiles <- sapply(1:99/100, qlnorm, log(means), seq(.5,.8,length.out=length(means)))
    
    ## default style with point predictions, color key and log-scale
    fanplot(quantiles = quantiles, probs = 1:99/100, means = means,
            observed = y, key.args = list(start = 1, space = .3), log = "y")
    
    ## with contour lines instead of a key, and different colors
    pal <- colorRampPalette(c("darkgreen", "gray93"))
    fanplot(quantiles = quantiles, probs = 1:99/100, observed = y,
            fan.args = list(fan.col = pal, ln = c(5,10,25,50,75,90,95)/100),
            observed.args = list(type = "b", pch = 19))
}

Run the code above in your browser using DataLab