Learn R Programming

qicharts (version 0.4.1)

tcc: Trellis Control Charts

Description

Run and control charts for multivariate data i trellis (grid) layout.

Usage

tcc(n, d, x, g1, g2, breaks, data, chart = c("run", "i", "mr", "xbar", "s",
  "t", "p", "c", "u", "g"), multiply = 1, freeze = NULL, exclude,
  sum.n = FALSE, neg.y = TRUE, cex = 1, pex = 1, ylim = NULL,
  date.format = NULL, prime = TRUE, flip = FALSE, dots.only = FALSE,
  main, xlab = "Time", ylab = "Indicator", plot = TRUE, print = FALSE,
  ...)

Arguments

n
Numeric vector of counts or measures to plot. Mandatory.
d
Numeric vector of sample sizes. Mandatory for P and U charts.
x
Subgrouping vector used for aggregating data and making x-labels. Mandatory for Xbar and S charts.
g1
Grouping vector 1 used for trellis layout (facets).
g2
Grouping vector 2used for trellis layout (facets).
breaks
Numeric vector of break points. Useful for splitting graph in two or more sections with separate center line and control limits.
data
Data frame containing variables.
chart
Type of control chart. Possible types are:
  • "run": run chart (default).
  • "i": individuals chart.
  • "mr": moving range chart.
  • "xbar": sample average chart.
  • "s": sample standard deviation chart.
  • "t": time between
multiply
Integer indicating a number to multiply y axis by, e.g. 100 for percents rather than proportions.
freeze
Number identifying the last data point to include in calculations of center and limits (ignored if breaks argument is given).
exclude
Numeric vector of data points to exclude from calculations of center and control lines.
sum.n
Logical value indicating whether the mean (default) or sum of counts should be plotted. Only relevant for run charts and I charts.
neg.y
Logical value. If TRUE (default), the y axis is allowed to be negative (only relevant for I and Xbar charts).
cex
Number indicating the amount by which text should be magnified.
pex
Number indicating the amount by which plotting symbols should be magnified.
ylim
Range of y axis.
date.format
Date format of x axis labels. See ?strftime for possible date formats.
prime
Logical value, If TRUE (default), control limits incorporate between-subgroup variation as proposed by Laney (2002). Only relevant for P and U charts.
flip
Logical. If TRUE rotates the plot 90 degrees.
dots.only
Logical value. If TRUE, data points are not connected by lines and runs analysis is not performed. Useful for comparison and funnel plots.
main
Character string specifying the title of the plot.
xlab
Character string specifying the x axis label.
ylab
Character string specifying the y axis label.
plot
Logical. If TRUE (default), plot chart.
print
Logical. if TRUE, prints return value.
...
Further arguments to ggplot function.

Value

  • A list of of class tcc containing values and parameters of the tcc plot.

Details

tcc() is a wrapper function that uses ggplot2 to create multivariate run and control charts. It takes up to two grouping variables to make one or two dimensional trellis plots.

Examples

Run this code
# Run chart of 24 random vaiables
tcc(rnorm(24))

# Build data frame for examples
d <- data.frame(x = rep(1:24, 4),
                mo = (rep(seq(as.Date('2013-1-1'),
                              length.out = 24,
                              by = 'month'),
                          4)),
                n = rbinom(4 * 24, 100, 0.5),
                d = round(runif(4 * 24, 90, 110)),
                g1 = rep(c('a', 'b'), each = 48),
                g2 = rep(c('A', 'B'), each = 24))

# Single, one-dimensional run chart
tcc(n, d, mo, data = subset(d, g1 == 'a' & g2 == 'A'))

# Run chart with one grouping variable and two groups
tcc(n, d, mo, g1 = g2, data = subset(d, g1 == 'a'))

# Run chart with two grouping variables
tcc(n, d, mo, g1 = g1, g2 = g2, data = d)

# I chart
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'i')

# P chart
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p')

# P chart with baseline fixed to the first 12 data points
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p', freeze = 12)

# P chart with two breaks
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p', breaks = c(12, 18))

# P chart with two data points excluded from calculations
tcc(n, d, mo, g1 = g1, g2 = g2, data = d, chart = 'p', exclude = c(12, 18))

Run the code above in your browser using DataLab