stsplot_time | R Documentation |
"sts"
Objects
These are the plot
variants of type=observed~time|unit
,
type=observed~time
, and type=alarm~time
for "sts"
objects (see the central "sts"
plot
-method for
an overview of plot types).
stsplot_time(x, units=NULL,
as.one=FALSE, same.scale=TRUE, par.list=list(), ...)
stsplot_time1(x, k=1, ylim=NULL,
axes=TRUE, xaxis.tickFreq=list("%Q"=atChange),
xaxis.labelFreq=xaxis.tickFreq, xaxis.labelFormat="%G\n\n%OQ",
epochsAsDate=x@epochAsDate,
xlab="time", ylab="No. infected", main=NULL,
type="s", lty=c(1,1,2), col=c(NA,1,4), lwd=c(1,1,1),
outbreak.symbol=list(pch=3, col=3, cex=1, lwd=1),
alarm.symbol=list(pch=24, col=2, cex=1, lwd=1),
legend.opts=list(),
dx.upperbound=0L, hookFunc=function(){},
.hookFuncInheritance=function() {}, ...)
stsplot_alarm(x, lvl=rep(1,ncol(x)),
xaxis.tickFreq=list("%Q"=atChange),
xaxis.labelFreq=xaxis.tickFreq, xaxis.labelFormat="%G\n\n%OQ",
epochsAsDate=x@epochAsDate,
xlab="time", ylab="", main=NULL,
outbreak.symbol=list(pch=3, col=3, cex=1, lwd=1),
alarm.symbol=list(pch=24, col=2, cex=1, lwd=1),
cex.yaxis=1, ...)
x |
an object of class |
units |
optional integer or character vector to select the units (=columns of
|
as.one |
logical indicating if all time series should be plotted
in a single frame (using |
same.scale |
logical indicating if all time series should be
plotted with the same |
par.list |
a list of arguments delivered to a call of
|
k |
the unit to plot, i.e., an element of |
ylim |
the y limits of the plot(s). Ignored if
|
axes |
a logical value indicating whether both axes should be drawn on the plot. |
xaxis.tickFreq , xaxis.labelFreq , xaxis.labelFormat |
arguments for |
epochsAsDate |
Boolean indicating whether to treat the epochs as
Date objects (or to transform them to dates such that the new x-axis
formatting is applied).
Default: Value of the |
xlab |
a title for the x axis. See |
ylab |
a title for the y axis. See |
main |
an overall title for the plot: see 'title'. |
type |
type of plot to do. |
lty |
vector of length 3 specifying the line type for the three
lines in the plot – see |
col |
Vector of length 3 specifying the color to use in the
plot. The first color is the fill color of the polygons for the
counts bars ( |
lwd |
Vector of length 3 specifying the line width of the three
elements to plot. See also the |
alarm.symbol |
a list with entries |
outbreak.symbol |
a list with entries |
legend.opts |
a list of arguments for the
where individual elements are only |
dx.upperbound |
horizontal change in the plotting of the upperbound line. Sometimes it can be convenient to offset this line a little for better visibility. |
lvl |
A vector of length |
cex.yaxis |
The magnification to be used for y-axis annotation. |
hookFunc |
a function that is called after all the basic plotting has be done, i.e., it is not possible to control formatting with this function. See Examples. |
.hookFuncInheritance |
a function which is altered by sub-classes plot method. Do not alter this function manually. |
... |
further arguments for the function |
The time series plot relies on the work-horse stsplot_time1
.
Its arguments are (almost) similar to plot.survRes
.
NULL
(invisibly).
The functions are called for their side-effects.
Michael Höhle and Sebastian Meyer
There is an autoplot
-method, which
implements ggplot2-based time-series plots of "sts"
objects.
The stsplot
help page gives an overview of other
types of plots for "sts"
objects.
data("ha.sts")
print(ha.sts)
plot(ha.sts, type=observed ~ time | unit) # default multivariate type
plot(ha.sts, units=c("mitt", "pank")) # selected units
plot(ha.sts, type=observed ~ time) # aggregated over all districts
## Hook function example
hookFunc <- function() grid(NA,NULL,lwd=1)
plot(ha.sts, hookFunc=hookFunc)
## another multivariate time series example plotted "as.one"
data("measlesDE")
plot(measlesDE, units=1:2, as.one=TRUE, legend.opts=list(cex=0.8))
## more sophisticated plots are offered by package "xts"
if (requireNamespace("xts"))
plot(as.xts.sts(measlesDE))
## Use ISO8601 date formatting (see ?strptime) and no legend
data("salmNewport")
plot(aggregate(salmNewport,by="unit"), xlab="Time (weeks)",
xaxis.tickFreq=list("%m"=atChange,"%G"=atChange),
xaxis.labelFreq=list("%G"=atMedian),xaxis.labelFormat="%G")
## Formatting also works for daily data (illustrated by artificial
## outbreak converted to sts object via 'linelist2sts')
set.seed(123)
exposureTimes <- as.Date("2014-03-12") + sample(x=0:25,size=99,replace=TRUE)
sts <- linelist2sts(data.frame(exposure=exposureTimes),
dateCol="exposure",aggregate.by="1 day")
## Plot it with larger ticks for days than usual
surveillance.options("stsTickFactors"=c("%d"=1, "%W"=0.33,
"%V"=0.33, "%m"=1.75, "%Q"=1.25, "%Y"=1.5, "%G"=1.5))
plot(sts,xaxis.tickFreq=list("%d"=atChange,"%m"=atChange),
xaxis.labelFreq=list("%d"=at2ndChange),xaxis.labelFormat="%d-%b",
xlab="Time (days)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.