Skip to contents

An enhanced replacement for pairs_diagonal_mosaic from the vcd package. This version fixes two bugs in the original (the labeling and alternate_labels arguments were hardcoded and ignored), changes the default labeling to labeling_border, and adds a counts convenience argument.

Usage

pairs_diagonal_mosaic(
  split_vertical = TRUE,
  margins = unit(0, "lines"),
  offset_labels = -0.4,
  offset_varnames = 0,
  gp = NULL,
  fill = "grey",
  labeling = labeling_border,
  alternate_labels = TRUE,
  counts = NULL,
  ...
)

# S3 method for class 'table'
pairs(x, diag_panel = pairs_diagonal_mosaic, ...)

Arguments

split_vertical

Logical; passed to mosaic. Default is TRUE.

margins

A unit object giving the margins around the mosaic. Default is unit(0, "lines").

offset_labels

Numeric; offset for the cell labels. Default is -0.4.

offset_varnames

Numeric; offset for the variable name labels. Default is 0.

gp

A gpar object for the mosaic tiles, or NULL (default) to use fill.

fill

Either a color name or a function mapping an integer to a vector of colors (e.g. a shading function). Default is "grey".

labeling

A labeling function such as labeling_border or labeling_values. Default is labeling_border (no cell counts shown).

alternate_labels

Logical; whether to alternate label positions on the axes. Default is TRUE.

counts

Controls cell-count display as a shortcut: FALSE forces labeling = labeling_border (no counts); TRUE forces labeling = labeling_values (show counts). When NULL (default), the labeling argument is used as-is.

...

Additional arguments passed to vcd:::pairs.table.

x

A contingency table (object of class "table").

diag_panel

A "grapcon_generator" function or a panel function for the diagonal cells. Defaults to the vcdExtra version of pairs_diagonal_mosaic.

Value

A function of class "grapcon_generator" suitable for use as the diag_panel argument in pairs.table.

Details

A companion pairs.table method is also provided that uses this improved function as the default diagonal panel.

The function follows the "grapcon_generator" pattern used throughout vcd: calling pairs_diagonal_mosaic(...) returns a function suitable for passing as the diag_panel argument of pairs.table.

The original vcd::pairs_diagonal_mosaic has two bugs: (1) the labeling argument is accepted but then hardcoded to labeling_values inside the returned function, and (2) alternate_labels is similarly hardcoded to TRUE. This version fixes both, making those arguments work as documented.

pairs.table is an S3 method for pairs that overrides the version in vcd solely to change the default diag_panel to the improved pairs_diagonal_mosaic defined in this package. All actual rendering is delegated to vcd:::pairs.table.

Examples

data(Hoyt, package = "vcdExtra")
pred_tab <- margin.table(Hoyt, c("Rank", "Occupation", "Sex"))

# Default: no cell counts in diagonal panels
pairs(pred_tab)


# Turn off counts explicitly (same as default)
pairs(pred_tab, diag_panel_args = list(counts = FALSE))


# Show cell counts in diagonal panels
pairs(pred_tab, diag_panel_args = list(counts = TRUE))


# Use residual shading for off-diagonal panels
pairs(pred_tab, gp = shading_Friendly)