These functions generate labeling functions that produce labels for strucplots.
labeling_cells(labels = TRUE, varnames = TRUE,
abbreviate_labels = FALSE, abbreviate_varnames = FALSE,
gp_text = gpar(), lsep = ": ", lcollapse = "\n",
just = "center", pos = "center", rot = 0,
margin = unit(0.5, "lines"), clip_cells = TRUE,
text = NULL, ...)
labeling_list(gp_text = gpar(), just = "left", pos = "left", lsep = ": ",
sep = " ", offset = unit(c(2, 2), "lines"),
varnames = TRUE, cols = 2, ...)
A function with arguments:
"dimnames"
attribute from the visualized contingency
table, or the visualized table itself from which the
"dimnames"
attributes will then be extracted.
vector of logicals indicating the split directions.
integer vector of conditioning dimensions
vector of logicals indicating, for each dimension, whether labels for the factor levels should be drawn or not. Values are recycled as needed.
vector of logicals indicating, for each dimension, whether variable names should be drawn. Values are recycled as needed.
vector of integers or logicals indicating,
for each dimension, the number of characters the labels should be
abbreviated to.
TRUE
means 1 character, FALSE
causes no abbreviation.
Values are recycled as needed.
vector of integers or logicals indicating,
for each dimension, the number of characters the variable
(i.e., dimension) names should be abbreviated to.
TRUE
means 1 character, FALSE
causes no abbreviation.
Values are recycled as needed.
object of class "gpar"
used for the text drawn.
character that separates variable names from the factor levels.
character that separates the factor levels (only used for
labeling_list
).
object of class "unit"
of length 2 specifying the
offset in x- and y-direction of the text block drawn under the
strucplot (only used for labeling_list
).
number of text columns (only used for
labeling_list
).
character that separates several variable name/factor
level-combinations. Typically a line break.
(Only used for labeling_cells
.)
character string of length 1 (labeling_list
)
or at most 2 (labeling_cells
) specifying the labels'
horizontal position and justification (horizontal and vertical for
labeling_cells
).
rotation angle in degrees, used for all labels (only used
for labeling_cells
).
object of class "unit"
(a numeric value is
converted to "lines"
) specifying an offset from the cell
borders (only used for labeling_cells
).
logical indicating whether text should be clipped at
the cell borders (only used for labeling_cells
).
Optionally, a character table of the same dimensions than
the contingency table whose entries will then be used instead of
the labels. NA
entries are not drawn.
This allows custom cell annotations (see examples).
Only used for labeling_cells
.
Currently not used.
David Meyer David.Meyer@R-project.org
These functions generate labeling functions that can add different
kinds of labels to an existing plot. Typically they are
supplied to strucplot
which then generates and calls
the labeling function. They assume that a strucplot has been drawn
and the corresponding viewport structure is pushed, so that by
navigating through the viewport tree the labels can be positioned
appropriately.
This help page only documents labeling_list
and
labeling_cells
; more functions are described on the help page
for labeling_border
.
The functions can also be used ‘stand-alone’ as shown in the examples.
Using labeling_list
will typically necessitate a bottom margin
adjustment.
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.
tools:::Rd_expr_doi("10.18637/jss.v017.i03") and available as
vignette("strucplot")
.
labeling_border
,
structable
,
grid.text
data("Titanic")
mosaic(Titanic, labeling = labeling_cells)
mosaic(Titanic, labeling = labeling_list)
## A more complex example, adding the observed frequencies
## to a mosaic plot:
tab <- ifelse(Titanic < 6, NA, Titanic)
mosaic(Titanic, pop = FALSE)
labeling_cells(text = tab, margin = 0)(Titanic)
Run the code above in your browser using DataLab