add_statline.RdThis function adds a statistical line or curve to an existing scplot
object. Various statistical functions are available such as mean, median,
min, max, quantile, standard deviation, moving average, and trend lines.
add_statline(
object,
stat = c("mean", "median", "min", "max", "quantile", "sd", "mad", "trend",
"moving mean", "moving median", "loreg", "lowess", "loess", "trendA",
"trendA theil-sen", "trendA bisplit", "trendA trisplit"),
phase = NULL,
color = NULL,
linewidth = NULL,
linetype = NULL,
variable = NULL,
label = NULL,
segmented = NULL,
case = NULL,
...
)An scplot object (class scplot) returned from the scplot()
function.
A character string for defining a statistical line or curve to be
plotted. Main options are "mean", "median", "min", "max",
"quantile", "sd", "mad", "trend", "moving mean", "moving median", "loreg" (local regression using loess).
Either a numeric or a character vector specifying the reference phase (see details).
A character string or a number defining the color of an element.
A number with the width of the line.
A character string with the line type: "solid", "dashed", "dotted"
Name of the dataline variable to apply the style.
A character string which is used to set the label in a legend.
Logical. If TRUE, the statline is plotted separately for
each phase. The default is NULL, where sensible settings are applied based
on the stat and phase arguments.
Either a numeric or a character vector specifying the case(s) for which the statline is plotted. The default is NULL, which applies the statline to all cases.
additional parameters passed to the statistical function.
An object of class scplot (seescplot()) with changed element
statlines.
The phase argument defines the reference phase for some
statistical functions ("median", "mean", "min", "max", "quantile", "trend"). The default is NULL which calculates and plots statistics for
each phase separately. The arguments takes a numeric vector (phase
number(s)) or a character vector (phase name(s)). When more than one phase
is defines, statistics are based on the combined values of these phases.
phase = all will select all phases. Various methods for a trend line
exist that can be set with method argument: The default is based on an
OLS regression, "theil-sen" on a nonparametric regression, and
"bisplit" / "trisplit" are two median based approaches. Some of the
functions defined in stat have additional arguments. The mean()
function has a trim argument (e.g. trim = 0.1). quantile() has a
proportion argument (e.g. prob = 0.75 for calculating the 75% quantile).
moving mean and moving median have a lag argument (e.g. lag = 2). The
local-regression curve function "lowess" (or "loreg") has a proportion
argument (e.g. f = 0.5; see lowess()) and the local-regression curve
function "loess" has a span argument (e.g. span = 0.75; see loess()).