cotabplot
is a generic function for creating trellis-like
coplots (conditional plots) for contingency tables.cotabplot(x, ...)
## S3 method for class 'default':
cotabplot(x, cond = NULL,
panel = cotab_mosaic, panel_args = list(),
margins = rep(1, 4), layout = NULL,
text_gp = gpar(fontsize = 12), rect_gp = gpar(fill = grey(0.9)),
pop = TRUE, newpage = TRUE,
...)
## S3 method for class 'formula':
cotabplot(formula, data = NULL, \dots)
panel
if this is
a panel-generating function inheriting from class "grapcon_generator"
."unit"
of length 4, or
a numeric vector of length 4. The elements are recycled as needed.
giving the margins around the whole plot."gpar"
used for the text in the panel titles."gpar"
used for the rectangles with the panel titles.data
. It has to be of type ~ x + y | z
where z
is/are the conditioning variable(s) used."table"
or "ftable"
.cotabplot
is a generic function designed to create coplots or
conditional plots (see Cleveland, 1993, and Becker, Cleveland, Shyu, 1996)
similar to coplot
but for contingency tables.
cotabplot
takes on computing the conditioning information
and setting up the trellis display, and then relies on a panel function
to create plots from the full table and the conditioning information.
A simple example would be a contingency table tab
with margin
names "x"
, "y"
and "z"
. To produce this plot
either the default interface can be used or the formula interface via
cotabplot(tab, "z")
cotabplot(~ x + y | z, data = tab)
The panel function needs to be of the form
panel(x, condlevels)
where x
is the full table (tab
in the example above)
and condlevels
is a named vector with the levels (e.g.,
c(z = "z1")
in the example above).
Alternatively, panel
can also be a panel-generating function
of class "grapcon_generator"
which creates a function with the
interface described above. The panel-generating function is called
with the interface
panel(x, condvars, ...)
where again x
is the full table, condvars
is now only
a vector with the names of the conditioning variables (and not their
levels, e.g., "z"
in the example above). Further arguments
can be passed to the panel-generating function via ...
which
also includes the arguments set in panel_args
.
Suitable panel-generating functions for mosaic, association and sieve
plots can be found at cotab_mosaic
.
A description of the underlying ideas is given in Zeileis, Meyer, Hornik
(2005).Cleveland, W.S. (1993), Visualizing Data, Summit, New Jersey: Hobart Press.
Meyer, D., Zeileis, A., and Hornik, K. (2006),
The strucplot framework: Visualizing multi-way contingency tables with
vignette("strucplot")
.
Zeileis, A., Meyer, D., Hornik K. (2007), Residual-based shadings for visualizing (conditional) independence, Journal of Computational and Graphical Statistics, 16, 507--525.
cotab_mosaic
,
cotab_coindep
,
co_table
,
coindep_test
data("UCBAdmissions")
cotabplot(~ Admit + Gender | Dept, data = UCBAdmissions)
cotabplot(~ Admit + Gender | Dept, data = UCBAdmissions, panel = cotab_assoc)
ucb <- cotab_coindep(UCBAdmissions, condvars = "Dept", type = "assoc",
n = 5000, margins = c(3, 1, 1, 3))
cotabplot(~ Admit + Gender | Dept, data = UCBAdmissions, panel = ucb)
Run the code above in your browser using DataLab