strucplot | R Documentation |
This modular function visualizes certain aspects of high-dimensional contingency tables in a hierarchical way.
strucplot(x, residuals = NULL, expected = NULL,
condvars = NULL, shade = NULL, type = c("observed", "expected"),
residuals_type = NULL, df = NULL, split_vertical = NULL,
spacing = spacing_equal, spacing_args = list(),
gp = NULL, gp_args = list(),
labeling = labeling_border, labeling_args = list(),
core = struc_mosaic, core_args = list(),
legend = NULL, legend_args = list(),
main = NULL, sub = NULL, margins = unit(3, "lines"),
title_margins = NULL, legend_width = NULL,
main_gp = gpar(fontsize = 20), sub_gp = gpar(fontsize = 15),
newpage = TRUE, pop = TRUE, return_grob = FALSE,
keep_aspect_ratio = NULL, prefix = "", ...)
x |
a contingency table in array form, with optional category
labels specified in the |
residuals |
optionally, an array of residuals of the same dimension
as |
expected |
optionally, an array of expected values of the same dimension
as |
df |
degrees of freedom passed to the shading functions
used for inference. Will be calculated (and overwritten if
specified) if both |
condvars |
number of conditioning variables, if any; those are
expected to be ordered first in the table.
This information is used for computing the expected values, and is
also passed to the spacing functions (see |
shade |
logical specifying whether |
residuals_type |
a character string indicating the type of
residuals to be computed when none are supplied.
If |
type |
a character string indicating whether the observed or the expected values of the table should be visualized. |
split_vertical |
vector of logicals of length |
spacing |
spacing object, spacing function, or a corresponding
generating function (see details and |
spacing_args |
list of arguments for the spacing-generating function, if specified. |
gp |
object of class |
gp_args |
list of arguments for the shading-generating function, if specified. |
labeling |
either a logical, or a labeling function, or a corresponding
generating function (see details and |
labeling_args |
list of arguments for the labeling-generating function, if specified. |
core |
either a core function, or a corresponding generating
function (see details). Currently, generating functions for
mosaic plots ( |
core_args |
list of arguments for the core-generating function, if specified. |
legend |
either a legend-generating function, or a legend
function (see details and |
legend_args |
list of arguments for the legend-generating function, if specified. |
main |
either a logical, or a character string used for plotting
the main title. If |
sub |
a character string used for plotting the subtitle.
If |
margins |
either an object of class |
title_margins |
either an object of class |
legend_width |
An object of class |
pop |
logical indicating whether the generated viewport tree should be removed at the end of the drawing or not. |
main_gp , sub_gp |
object of class |
newpage |
logical indicating whether a new page should be created for the plot or not. |
return_grob |
logical. Should a snapshot of the display be returned as a grid grob? |
keep_aspect_ratio |
logical indicating whether the aspect ratio should be
fixed or not. If unspecified, the default is |
prefix |
optional character string used as a prefix for the generated viewport and grob names. |
... |
For convenience, list of arguments passed to the labeling-generating function used. |
This function—usually called by higher-level functions such as
assoc
and mosaic
—generates conditioning
plots of contingency tables. First, it sets up a set of viewports for
main- and subtitles, legend, and the actual plot region. Then,
residuals are computed as needed from observed and expected
frequencies, where the expected frequencies are optionally computed
for a specified independence model. Finally, the specified functions
for spacing, gp, main plot, legend, and labeling are called to produce
the plot. The function invisibly returns the "structable"
object
visualized.
Most elements of the plot, such as the core function, the spacing
between the tiles, the shading of the tiles, the labeling, and the
legend, are modularized in graphical appearance control (“grapcon”)
functions and specified as parameters. For
each element foo (= spacing
, labeling
, core
,
or legend
), strucplot
takes two arguments:
foo and foo_args, which can be used to specify the
parameters in the following alternative ways:
Passing a suitable function to foo which subsequently
will be called from strucplot
to compute shadings, labelings,
etc.
Passing a corresponding generating function to foo,
along with parameters passed to foo_args, that generates such a
function. Generating functions must inherit from classes
"grapcon_generator"
and "foo"
.
Except for the shading functions (shading_bar), passing foo(foo_args) to the foo argument.
For shadings and spacings, passing the final parameter object itself; see the corresponding help pages for more details on the data structures.
If legends are drawn, a ‘cinemascope’-like layout is used for the plot to preserve the 1:1 aspect ratio.
If type = "expected"
, the expected values are passed to the
observed
argument of the core function, and the observed
values to the expected
argument.
Although the gp
argument is typically used for shading, it can
be used for arbitrary modifications of the tiles' graphics parameters
(e.g., for highlighting particular cells, etc.).
Invisibly, an object of class "structable"
corresponding to the
plot. If return_grob
is TRUE
, additionally, the plot as
a grob object is returned in a grob
attribute.
The created viewports, as well as the tiles and bullets, are named and
thus can conveniently be modified after a plot has been drawn (and
pop = FALSE
).
David Meyer David.Meyer@R-project.org
Meyer, D., Zeileis, A., and Hornik, K. (2006),
The strucplot framework: Visualizing multi-way contingency tables with
vcd.
Journal of Statistical Software, 17(3), 1-48.
\Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v017.i03")} and available as
vignette("strucplot")
.
assoc
,
mosaic
,
sieve
,
struc_assoc
,
struc_sieve
,
struc_mosaic
,
structable
,
doubledecker
,
labelings
,
shadings
,
legends
,
spacings
data("Titanic")
strucplot(Titanic)
strucplot(Titanic, core = struc_assoc)
strucplot(Titanic, spacing = spacing_increase,
spacing_args = list(start = 0.5, rate = 1.5))
strucplot(Titanic, spacing = spacing_increase(start = 0.5, rate = 1.5))
## modify a tile's color
strucplot(Titanic, pop = FALSE)
grid.edit("rect:Class=1st,Sex=Male,Age=Adult,Survived=Yes",
gp = gpar(fill = "red"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.