Learn R Programming

surveillance (version 1.8-3)

stsplot_spacetime: Map of Disease Incidence

Description

For each period (row) or for the overall period of the observed matrix of the "sts" object, a map showing the counts by region is produced. It is possible to redirect the output into files, e.g. to generate an animated GIF.

Usage

stsplot_spacetime(x, type, legend = NULL, opts.col = NULL, labels = TRUE,
                  wait.ms = 250, cex.lab = 0.7, verbose = FALSE,
                  dev.printer = NULL, ...)

Arguments

x
an object of class "sts".
type
a formula (see stsplot). For a map aggregated over time (no animation), use observed ~ 1 | unit, otherwise observed ~ 1 | unit * time.
legend
An object of type list containing the following items used for coloring
  • dx
{position increments in x direction} dy{position increments in y direction} x{position in x}

item

  • opts.col
  • use.color
  • labels
  • wait.ms
  • cex.lab
  • verbose
  • dev.printer
  • ...

itemize

  • ncolors

code

animation

See Also

Other stsplot types, and animate.sts for the new implementation.

Examples

Run this code
data("ha.sts")
print(ha.sts)

## map of total counts by district
plot(ha.sts, type=observed ~ 1 | unit)
## only show a sub-period total for two selected districts
plot(ha.sts[1:20,1:2], type=observed ~ 1 | unit)

# space-time animation
plot(aggregate(ha.sts,nfreq=13), type= observed ~ 1 | unit * time)

#Configure a png device printer to save the frames
dev.printer <- list(device=png, extension=".png", width=640, height=480,
                    name=file.path(tempdir(),"berlin"))

#Do the animation (without extra sleeping time between frames)
plot(aggregate(ha.sts,nfreq=13), type = observed ~ 1 | unit * time,
     wait.ms=0, dev.printer=dev.printer)

#Use ImageMagick (you might have to adjust the path to 'convert')
system(paste("convert -delay 50 ",dev.printer$name,
           "*.png ", dev.printer$name, "-animated.gif",sep=""))

Run the code above in your browser using DataLab