Learn R Programming

surveillance (version 1.5-4)

twinstim_epidataCS_animate: Spatio-Temporal Animation of a Continuous-Time Continuous-Space Epidemic

Description

Function for the animation of continuous-time continuous-space epidemic data, i.e. objects inheriting from class "epidataCS". There are three 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, since this function is compatible to the framework of the contributed Rpackage animation and respects the ani.options "interval" and "nmax" if this package is available.

Usage

## S3 method for class 'epidataCS':
animate(object, interval = c(0,Inf), time.spacing = NULL,
        nmax = NULL, sleep = NULL, legend.opts = list(), timer.opts = list(),
        pch = 15:18, col.current = "red", col.I = "#C16E41", col.R = "#B3B3B3",
        col.influence = "#FEE0D2", ...)

Arguments

object
an object inheriting from class "epidataCS".
interval
time range of the animation.
time.spacing
time interval for the animation steps. If NULL (the default), the events are plotted one by one. Thus, it is just the ordering of the events, which is shown. To plot the appearance of events proportionally to the exact time line,
nmax
maximum number of snapshots to generate. The default NULL means to take the value from ani.options("nmax") if the animation package is available, and no limitation (Inf) otherwise.
sleep
numeric scalar specyfing the artificial pause in seconds between two time points, or NULL (default), when this is taken from ani.options("interval") if the animation package is available, or set to 0.1 othe
pch, col
vectors of length equal to the number of event types specifying the point symbols and colors for events to plot (in this order). The vectors are recycled if necessary.
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
col.current
color of events when occuring.
col.I
color once infectious.
col.R
color event has once recovered. If NA, then recovered events will not be shown.
col.influence
color with which the influence region is drawn. Use NA if no influence regions should be drawn.
...
further graphical parameters passed to the plot-method of the SpatialPolygons-class.

encoding

latin1

See Also

plot.epidataCS for plotting the numbers of events by time (aggregated over space) or the locations of the events in the observation region W (aggregated over time).

The contributed Rpackage animation.

Examples

Run this code
data("imdepi")
  imdepiB <- subset(imdepi, type == "B")
  if (require("animation")) ani.options(interval = 0.1, nmax = 60)

  # Animate the first year of type B with a step size of 7 days
  animate(imdepiB, interval=c(0,365), time.spacing=7)

  # Animate the whole time range but with nmax=60 snapshots only and
  # omitting the painting of (quiet artificial) influence regions
  animate(imdepiB, time.spacing=NA, col.influence=NA, nmax=60)

  # Sequential animation of events
  animate(imdepiB, time.spacing=NULL, nmax=60)

  # Such an animation can be saved in various ways using the tools of
  # the animation package, e.g., saveHTML()
  if (require("animation")) {
    ani.options(outdir = tempdir())
    saveHTML(animate(imdepiB, interval=c(0,365), time.spacing=7),
             img.name = "imdepi_year1", htmlfile = "imdepi_animation.html",
             autobrowse = TRUE, title = "Animation of the first year",
             description = c("Take a look into the first-year dynamics."))
  }

Run the code above in your browser using DataLab