Learn R Programming

MSCMT (version 1.4.0)

ggplot.mscmt: Plotting Results of mscmt with ggplot2

Description

ggplot.mscmt plots results of mscmt based on ggplot.

Usage

# S3 method for mscmt
ggplot(
  data,
  mapping = aes(),
  what,
  type = c("gaps", "comparison", "placebo.gaps", "placebo.data", "p.value"),
  treatment.time,
  zero.line = TRUE,
  ylab,
  xlab = "Date",
  main,
  col,
  lty,
  lwd,
  legend = TRUE,
  bw = FALSE,
  date.format,
  unit.name,
  full.legend = TRUE,
  include.smooth = FALSE,
  include.mean = FALSE,
  include.synth = FALSE,
  draw.estwindow = TRUE,
  what.set,
  limits = NULL,
  alpha = 1,
  alpha.min = 0.1,
  exclude.units = NULL,
  exclude.ratio = Inf,
  ratio.type = c("rmspe", "mspe"),
  alternative = c("two.sided", "less", "greater"),
  draw.points = TRUE,
  control.name = "control units",
  size = 1,
  treated.name = "treated unit",
  labels = c("actual data", "synthsized data"),
  ...,
  environment = parent.frame()
)

Value

An object of class ggplot.

Arguments

data

An object of class "mscmt", usually obtained as the result of a call to function mscmt.

mapping

An object necessary to match the definition of the ggplot generic (passed to ggplot as is). Defaults to aes().

what

A character vector. Name(s) of the variables to be plotted. If missing, the (first) dependent variable will be used.

type

A character scalar denoting the type of the plot containing either "gaps", "comparison", "placebo.gaps", "placebo.data", or "p.value". Partial matching allowed, defaults to "placebo.gaps", if results of a placebo study are present, and to "gaps", else.

treatment.time

An optional scalar (numeric, character, or Date) giving the treatment time. If treatment.time is numeric, Jan 01 of that year will be used. If treatment.time is a character string, it will be converted to a Date and must thus be in an unambiguous format. A vertical dotted line at the given point in time is included in the plot.

zero.line

A logical scalar. If TRUE (default), a horizontal dotted line (at zero level) is plotted for "gaps" and "placebo.gaps" plots.

ylab

Optional label for the y-axis, automatically generated if missing.

xlab

Optional label for the x-axis, defaults to "Date".

main

Optional main title for the plot, automatically generated if missing.

col

Optional character vector with length 1 (for gaps plots) or 2 (for all other plot types). For comparison plots, col contains the colours for the actual and synthesized data, for placebo.plots (with full.legend==FALSE), col contains the colours for the treated unit and the control units. Automatically generated if missing.

lty

Optional numerical vector with length 1 (for gaps plots) or 2 (for all other plot types). For comparison plots, lty contains the linetypes for the actual and synthesized data, for placebo.plots (with full.legend==FALSE), col contains the linetypes for the treated unit and the control units. Automatically generated if missing.

lwd

Optional numerical vector with length 1 (for gaps plots) or 2 (for all other plot types). For comparison plots, lty contains the linewidths for the actual and synthesized data, for placebo.plots (with full.legend==FALSE), col contains the linewidths for the treated unit and the control units. Automatically generated if missing.

legend

A logical scalar. If TRUE (default), a legend is included in the plot.

bw

A logical scalar. If FALSE (default), the automatically generated colours and line types are optimized for a colour plot, if TRUE, the automatic colours and line types are set for a black and white plot.

date.format

A character string giving the format for the tick labels of the x axis as documented in strptime. Defaults to "%b %y" or "%Y", depending on the granularity of the data.

unit.name

A character string with the title of the legend for comparison and placebo plots. Defaults to "Estimation" for comparison and "Unit" for placebo plots.

full.legend

A logical scalar. If TRUE (default), a full legend of all units (donors) is constructed. If FALSE, only the treated and the control units are distinguished.

include.smooth

A logical scalar. If TRUE, a geometric smoother based on the control units is added to placebo plots. Default: FALSE.

include.mean

A logical scalar. If TRUE, the arithmetic mean of all control units is added to placebo plots. Default: FALSE.

include.synth

A logical scalar. If TRUE, the synthesized data for the treated unit are added to plots of type "placebo.data". Defaults to FALSE.

draw.estwindow

A logical scalar. If TRUE (default), the time range containing all optimization periods is shaded in the corresponding plots.

what.set

An optional character string for a convenient selection of multiple variables. Accepted values are "dependents", "predictors", and "all", which collects all dependent, all predictor, or all variables of both types, respectively. Overrides parameter what (if the latter is present).

limits

An optional vector of length 2 giving the range of the plot or NULL. If limits is numeric, Jan 01 of the corresponding years will be used. If limits is of type character, both strings will be converted to Dates (via as.Date) and must thus be in an unambiguous format.

alpha

Either a numerical scalar, a numerical vector of length corresponding to the number of units, or the character string "auto". If alpha is a numerical scalar (default with value 1), a fixed value for the alpha channel (transparency) is included for all units in placebo plots. If alpha is numeric and has length corresponding to the number of units, these values are assigned as alpha channel to the individual units. If "auto", the alpha channel information is obtained from the w weights of the control units.

alpha.min

A numerical scalar (default: 0.1). If alpha is set to "auto", the individual alpha channel information for control unit i is set to alpha.min + (1-alpha.min) * w[i].

exclude.units

An optional (default: NULL) character vector with names for control units which shall be excluded from placebo plots and p-value calculations.

exclude.ratio

A numeric scalar (default: Inf). Control units with a pre-treatment (r)mspe of more than exclude.ratio times the pre-treatment (r)mspe of the treated unit are excluded from placebo plots and p-value calculations.

ratio.type

A character string. Either rmspe (default) or mspe. Selects whether root mean squared errors or mean squared errors are considered for the exclusion of control units (see exclude.ratio).

alternative

A character string giving the alternative of the test for plots of type "p.value". Either "two.sided" (default), "less", or "greater".

draw.points

A logical scalar. If TRUE (default), points are added to the line plots to enhance visibility.

control.name

A character string for the naming of the non-treated units in placebo plots. Defaults to "control units".

size

A numerical scalar (default: 1). If draw.points is TRUE (default), size specifies the size of the points.

treated.name

A character string giving the label for the treated unit. Defaults to "treated unit".

labels

A character vector of length 2 giving the labels for the actual and synthesized data. Defaults to c("actual data","synthsized data").

...

Necessary to match the definition of the "ggplot" generic (passed to ggplot as is).

environment

An object necessary to match the definition of the "ggplot" generic (passed to ggplot as is). Defaults to parent.frame().

Details

A unified plot method for gaps plots, comparison of treated and synthetic values, as well as plots for placebo studies, based on ggplot. ggplot.mscmt is the preferred plot method and has more functionality than plot.mscmt.