Plotting the Evolution of an Epidemic
epidata_plot.RdFunctions for plotting the evolution of epidemics. The plot
methods for classes "epidata" and
"summary.epidata" plots the numbers of susceptible, infectious and
recovered (= removed) individuals by step functions along the time axis. The
function stateplot shows individual state changes along the time axis.
Usage
# S3 method for class 'summary.epidata'
plot(x,
lty = c(2, 1, 3), lwd = 2,
col = c("#1B9E77", "#D95F02", "#7570B3"), col.hor = col, col.vert = col,
xlab = "Time", ylab = "Number of individuals",
xlim = NULL, ylim = NULL, legend.opts = list(), do.axis4 = NULL,
panel.first = grid(), rug.opts = list(),
which.rug = c("infections", "removals", "susceptibility", "all"), ...)
# S3 method for class 'epidata'
plot(x, ...)
stateplot(x, id, ...)Arguments
- x
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. Theplotmethod for class"epidata"is a simple wrapper forplot.summary.epidataimplemented asplot(summary(x, ...)).- lty, lwd
vectors of length 3 containing the line types and widths, respectively, for the numbers of susceptible, infectious and removed individuals (in this order). By default, all lines have width 1 and the line types are dashed (susceptible), solid (infectious) and dotted (removed), respectively. To omit the drawing of a specific line, just set the corresponding entry in
ltyto 0. The vectors are recycled if necessary. For information about the differentltyandlwdcodes, see the help pages ofpar.- col, col.hor, col.vert
vectors of length 3 containing the line colors for the numbers of susceptible, infectious and removed individuals (in this order).
col.hordefines the color for the horizontal parts of the step function, whilstcol.vertdefines the color for its vertical parts. The argumentcolis just short forcol.hor = colandcol.vert = col. The defaultcolvector corresponds tobrewer.pal("Dark2",n=3)from the RColorBrewer package. The vectors are recycled if necessary. For information about the possible values ofcol, see the help pages ofpar.- xlab, ylab
axis labels, default to "Time" and "Number of individuals", respectively.
- xlim, ylim
the x and y limits of the plot in the form
c(xmin, xmax)andc(ymin, ymax), respectively. By default, these are chosen adequately to fit the time range of the epidemic and the number of individuals.- legend.opts
if this is a list (of arguments for the
legendfunction), a legend will be plotted. The defaults are as follows:x:"topright"inset:c(0,0.02)legend:c("susceptible", "infectious", "removed")lty,lwd,col:same as the arguments
lty,lwd, andcol.horof the main functionbty:"n"
- do.axis4
logical indicating if the final numbers of susceptible and removed individuals should be indicated on the right axis. The default
NULLmeansTRUE, ifxrepresents a SIR epidemic andFALSEotherwise, i.e. if the epidemic is SI, SIS or SIRS.- panel.first
an expression to be evaluated after the plot axes are set up but before any plotting takes place. By default, a standard grid is drawn.
- rug.opts
either a list of arguments passed to the function
rugorNULL(orNA), in which case norugwill be plotted. By default, the argumentticksizeis set to 0.02,colis set to the color according towhich.rug(black if this is"all"), andquietis set toTRUE. Note that the argumentx, which contains the locations for therugis fixed internally and can not be modified. The argumentwhich.rug(see below) determines the locations to mark.- which.rug
By default, tick marks are drawn at the time points of infections. Alternatively, one can choose to mark only
"removals","susceptibilities"(i.e. state change from R to S) or"all"events.- id
single character string or factor of length 1 specifying the individual for which the
stateplotshould be established.- ...
For
plot.summary.epidata: further graphical parameters passed toplot,linesandaxis, e.g.main,las,cex.axis(etc.) andmgp.
Forplot.epidata: arguments passed toplot.summary.epidata.
Forstateplot: arguments passed toplot.stepfunorplot.function(ifidhad no events during the observation period). By default,xlab="time",ylab="state",xlim=attr(x,"timeRange"),xaxs="i"anddo.points=FALSE.
Value
plot.summary.epidata (and plot.epidata) invisibly returns the
matrix used for plotting, which contains the evolution of the three
counters.stateplot invisibly returns the function, which was plotted,
typically of class "stepfun", but maybe of class "function",
if no events have been observed for the individual in question (then the
function always returns the initial state). The vertical axis of
stateplot can range from 1 to 3, where 1 corresponds to
Susceptible, 2 to Infectious and 3 to Removed.
See also
summary.epidata for the data, on which the plots are based.
animate.epidata for the animation of epidemics.