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.

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, ...)



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


numeric vector of probabilities with values between 0 and 1.


(optional) numeric vector of point forecasts.


(optional) numeric vector of observed values.


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


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.


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


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


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.


axis ranges.


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


axis labels.


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.


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


Sebastian Meyer

See also

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


## 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))