surveillance (version 1.12.1)

epidata_animate: Spatio-Temporal Animation of an Epidemic

Description

Function for the animation of epidemic data, i.e. objects inheriting from class "epidata". This only works with 1- or 2-dimensional coordinates and is not useful if some individuals share the same coordinates (overlapping). There are two types of animation, see argument time.spacing. Besides the direct plotting in the Rsession, it is also possible to generate a sequence of graphics files to create animations outside R.

Usage

## S3 method for class 'summary.epidata':
animate(object, main = "An animation of the epidemic",
        pch = 19, col = c(3, 2, gray(0.6)), time.spacing = NULL,
        sleep = quote(5/.nTimes), legend.opts = list(), timer.opts = list(),
        end = NULL, generate.snapshots = NULL, ...)

## S3 method for class 'epidata': animate(object, ...)

Arguments

object
an object inheriting from class "epidata" or "summary.epidata". In the former case, its summary is calculated and the function continues as in the latter case, passing all ... arguments to the summ
main
a main title for the plot, see also title.
pch, col
vectors of length 3 specifying the point symbols and colors for susceptible, infectious and removed individuals (in this order). The vectors are recycled if necessary. By default, susceptible individuals are marked as filled green circles,
time.spacing
time interval for the animation steps. If NULL (the default), the events are plotted one by one with pauses of sleep seconds. Thus, it is just the ordering of the events, which is shown. To plot the appea
sleep
time in seconds to Sys.sleep before the next plotting event. By default, each artificial pause is of length 5/.nTimes seconds, where .nTimes is the number of events (inf
legend.opts
either a list of arguments passed to the legend function or NULL (or NA), in which case no legend will be plotted. All necessary arguments have sensible defaults and need
timer.opts
either a list of arguments passed to the legend function or NULL (or NA), in which case no timer will be plotted. All necessary arguments have sensible defaults and need n
end
ending time of the animation in case of time.spacing not being NULL. By default (NULL), time stops after the last event.
generate.snapshots
By default (NULL), the animation is not saved to image files but only shown on the on-screen device. In order to print to files, time.spacing must not be NULL, a screen device must be available, and there
...
further graphical parameters passed to the basic call of plot, e.g. las, cex.axis (etc.) and mgp.

See Also

summary.epidata for the data, on which the plot is based. plot.epidata for plotting the evolution of an epidemic by the numbers of susceptible, infectious and removed individuals.

The contributed Rpackage animation.

Examples

Run this code
data("fooepidata")
(s <- summary(fooepidata))

# plot the ordering of the events only
animate(s, sleep=0.01)   # or: animate(fooepidata)

# with timer (animate only up to t=10)
animate(s, time.spacing=0.1, end=10, sleep=0.01)

# Such an animation can be saved in various ways using tools of
# the animation package, e.g., saveHTML()
if (interactive() && require("animation")) {
  oldwd <- setwd(tempdir())  # to not clutter up the current working dir
  saveHTML({
    par(bg="white")  # default "transparent" is grey in some browsers
    animate(s, time.spacing=1, sleep=0, generate.snapshots="epiani")
  }, use.dev=FALSE, img.name="epiani", ani.width=600, interval=0.5)
  setwd(oldwd)
}

Run the code above in your browser using DataLab