Skip to contents

A simple ggplot2 variant of stsplot_time, based on a “tidy” version of the "sts" object via tidy.sts. It uses a date axis and thus only works for time series indexed by dates or with a standard frequency (daily, (bi-)weekly, or monthly).


autoplot.sts(object, population = FALSE, units = NULL,
    = FALSE, scales = "fixed", width = NULL, ...)



an object of class "sts".


logical indicating whether observed(object) should be divided by population(object). The population argument can also be a scalar, which is used to scale the denominator population(object), i.e., observed(object) is divided by population(object) / population. For instance, if population(object) contains raw population numbers, population = 1000 could be used to plot the incidence per 1000 inhabitants.


optional integer or character vector to select the units (=columns of object) to plot. The default (NULL) is to plot all time series.

logical indicating if all time series should be plotted in one panel with geom_line. By default, the time series are plotted in separate panels (using geom_col).


passed to facet_wrap (for By default, all panels use a common ylim (and xlim).


bar width, passed to geom_col. Defaults to 7 for weekly time series.


unused (argument of the generic).


a "ggplot" object.


Sebastian Meyer

See also

stsplot_time for the traditional plots.


## compare traditional plot() with ggplot2-based autoplot.sts()
if (requireNamespace("ggplot2")) {
    plot(measlesDE, units = 1:2)
    autoplot.sts(measlesDE, units = 1:2)

if (surveillance.options("allExamples"))
## weekly incidence: population(measlesDE) gives population fractions,
## which we need to multiply by the total population
if (require("ggplot2")) {
    autoplot.sts(measlesDE, population = 1000000/82314906) +
        ylab("Weekly incidence [per 1'000'000 inhabitants]")