Animated Maps and Time Series of Disease Counts or Incidence
sts_animate.RdThe animate-method for sts objects
iterates over time points, plotting maps of the current|cumulative
counts|incidence via stsplot_space, optionally
including a time series chart below the map to track the epidemic curve.
It is worth using functionality of the animation package
(e.g., saveHTML) to directly export the
animation into a useful format.
Usage
# S3 method for class 'sts'
animate(object, tps = NULL, cumulative = FALSE,
population = NULL, at = 10, ...,
timeplot = list(pos = 1, size = 0.3, fill = TRUE),
sleep = 0.5, verbose = interactive(), draw = TRUE)Arguments
- object
an object of class
"sts"or a matrix of counts, i.e.,observed(stsObj), where especiallycolnames(x)have to be contained inrow.names(map). If a matrix, themapobject has to be provided explicitly (as part of...).- tps
a numeric vector of one or more time points at which to plot the map. The default
tps=NULLmeans the whole time period1:nrow(object).- cumulative
logical specifying if the cumulative counts/incidence over time should be plotted. The cumulative incidence is relative to the population from the first time point
tps[1]throughout the whole animation, whilecumulative=FALSEcomputes the incidence from the current population numbers.- population,at,...
arguments for
stsplot_space.- timeplot
if a list and package gridExtra is available, a time series chart of the counts along the selected time points
tpswill be plotted next to the map. The list elements determine both the positioning of this plot (pos,size, andfill) and its appearance. The defaultpos=1andsize=0.3arguments put the time series plot below the map, using 30% of the total plot height. The logical valuefillindicates whether to make the panel as big as possible (default: TRUE). An alternative tofill=FALSEis to manually specify anaspect(ratio) value intimeplot. Other list elements are arguments for the internal (and currently undocumented) functionstsplot_timeSimple. For example,inactiveandactiveare lists of graphical parameters (e.g.,col) determining the appearance of the bars (e.g., default color is grey when inactive and black when active), and the booleanas.Datedetermines whether dates should be put on the x-axis (instead of thetpsindexes).- sleep
time to wait (
Sys.sleep) between subsequent snapshots (only ifdev.interactive), in seconds.- verbose
logical indicating if a
txtProgressBarshould be shown during generation of the animation – which may take a while. Default is to do so ininteractivesessions.- draw
logical indicating if the produced plots at each time point should be drawn directly (the default) or not. The setting
draw = FALSEis useful if one would like to manually arrange the plots, which are always returned invisibly in a list of lengthlength(tps).
Value
(invisibly) a list of the length(tps) sequential plot objects.
These are of class "gtable" (from gtable)
if the timeplot is included, otherwise of class
"\code{trellis".
See also
the other plot types documented in stsplot for static
time series plots and maps.
Examples
data("measlesWeserEms")
## animate the weekly counts of measles (during weeks 12-16 only, for speed)
if (interactive() && require("animation")) {
oldwd <- setwd(tempdir()) # to not clutter up the current working dir
saveHTML(animate(measlesWeserEms, tps=12:16),
title="Evolution of the measles epidemic in the Weser-Ems region",
ani.width=500, ani.height=600)
setwd(oldwd)
}
if (FALSE) { # \dontrun{
## animate the weekly incidence of measles (per 100'000 inhabitants),
## and label the time series plot with dates in a specified format
animate(measlesWeserEms, tps=12:16,
population = measlesWeserEms@map$POPULATION / 100000,
timeplot = list(as.Date = TRUE,
scales = list(x = list(format = "%G/%V"))))
} # }