Skip to contents

Computes pairwise associations (Cramer's V or -log10 p-values) across all categorical/factor columns in a data frame and renders an association matrix plot via corrplot. This complements correlation_plot for numeric variables.

Usage

plot_categorical_associations(
  data,
  cols = NULL,
  method = c("cramer_v", "p_value"),
  title = "Categorical Association Matrix",
  fill_colors = c("#FFFFFF", "#9D2235"),
  tl.cex = 0.8,
  number.cex = 0.75,
  show_coef = TRUE,
  ...
)

Arguments

data

A data frame or tibble.

cols

Optional character vector of column names to include. If NULL, all factor and character columns are selected.

method

Association metric: "cramer_v" (Cramer's V correlation, default) or "p_value" (\(-\log_{10}(p)\)). For "p_value", 2x2 pairs use the exact test of exact2x2 and larger tables use the asymptotic Pearson chi-squared test, so every pair is on the same deterministic scale (a simulated Fisher p-value cannot fall below 1 / (B + 1)). Values are capped at 16.

title

Plot title (defaults to "Categorical Association Matrix").

fill_colors

Character vector for the color gradient (defaults to Temple palette).

tl.cex

Label character expansion (default 0.8).

number.cex

Numeric value character expansion inside circles (default 0.75).

show_coef

Logical (default TRUE); whether to print coefficients.

...

Additional arguments passed to corrplot.

Value

Invisibly, the association matrix.

Examples

df <- data.frame(
  A = factor(sample(c("Yes", "No"), 50, replace = TRUE)),
  B = factor(sample(c("High", "Low"), 50, replace = TRUE)),
  C = factor(sample(c("Group1", "Group2", "Group3"), 50, replace = TRUE))
)
plot_categorical_associations(df)