epidata_animate | R Documentation |
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 R session, it is
also possible to generate a sequence of graphics files to create animations
outside R.
## 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, ...)
object |
an object inheriting from class |
main |
a main title for the plot, see also |
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,
infectious individuals as filled red circles and removed individuals as
filled gray circles. Note that the symbols are iteratively drawn
(overlaid) in the same plotting region as time proceeds.
For information about the possible values of |
time.spacing |
time interval for the animation steps. If |
sleep |
time in seconds to |
legend.opts |
either a list of arguments passed to the
|
timer.opts |
either a list of arguments passed to the
Note that the argument |
end |
ending time of the animation in case of |
generate.snapshots |
By default (
will store the animation steps in pdf-files in the current
working directory, where the file names each end with the time point
represented by the corresponding plot. Because the variables |
... |
further graphical parameters passed to the basic call of |
Sebastian Meyer
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 R package animation.
data("hagelloch")
(s <- summary(hagelloch))
# plot the ordering of the events only
animate(s) # or: animate(hagelloch)
# with timer (animate only up to t=10)
animate(s, time.spacing=0.1, end=10, sleep=0.01,
legend.opts=list(x="topleft"))
# 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, legend.opts=list(x="topleft"),
generate.snapshots="epiani")
}, use.dev=FALSE, img.name="epiani", ani.width=600, interval=0.5)
setwd(oldwd)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.