tabxplor

CRAN status R-CMD-check Codecov test coverage

tabxplor makes cross-tables and regression models readable at a glance for data exploration. It builds a table with percentages, weighted counts, confidence intervals, tests — and colors highlight the cells that stand out from the total or reference, only when the difference is statistically solid, to spot the structure of your data immediately.

The tables below are screenshots of the package website, where they are live html: GitHub strips the colors out of a README. Above each one is the code that built it.

Installation

install.packages("tabxplor", dependencies = TRUE)

# Development version:
# install.packages("devtools")
devtools::install_github("BriceNocenti/tabxplor")

A quick look

A simple cross-table with row percentages: shades of blue mean the cell is over-represented compared to the total row, shades of yellow to red mean it is under-represented.

gss <- gss_cat_data_formatting() # a cleaned-up version of forcats::gss_cat

tab(gss, race, party3, pct = "row", color = "difference")

Party identification by race, in row percentages: cells over-represented compared to the total row are blue, under-represented ones yellow to red.

Several column variables can be crossed at once for series of Yes/No survey questions. With color_signif = "grey_non_signif", cells that are not significantly different from the total are greyed out, so every colored figure is a solid one. Use wt = for weighted or survey data. Example with FactoMineR tea data :

tea_when_vars <- c("breakfast", "tea.time", "evening", "lunch", "dinner", "always")
tab(facto_tea, SPC, all_of(tea_when_vars), pct = "row", 
    levels = "first", na = "drop", 
    color = "difference", ref = "first", color_signif = "grey_non_signif")

Six Yes/No questions about when tea is drunk, crossed with occupation: only the cells significantly different from the reference row keep a color, the others are greyed out.

The same visual language extends to regression models: tab_reg() detects a binary outcome and fits a logistic regression, coloring odds ratios by strength and greying the non-significant ones, with a default comparison between the modelised deviations and their crude/observed counterparts.

tab_reg(gss, outcome = "married", predictors = c("race", "age", "rincome"))

Logistic regression of being married on race, age and income: each modelled odds ratio sits beside its observed counterpart, colored by strength and greyed when not significant, over a model-fit footer.

The shape table under the regression: the observed curve of the outcome against age, over its observed range.

Or as a black and white table ready for publication:

options(tabxplor.theme = "print_ready")
tab_reg(gss, outcome = "married", predictors = c("race", "age", "rincome"))

The same regression table in the black-and-white publication theme: bold, italics and underlining replace the colors, on the same ladder of thresholds.

Export your tables

Any table exports with its colors to Excel, html or markdown (for Word, copy-paste from Excel) :

tab(gss, marital, race, pct = "row", color = "difference") |> tab_html()
tab(gss, marital, race, pct = "row", color = "difference") |> tab_xl()
tab(gss, marital, race, pct = "row", color = "difference") |> tab_xl(theme = "print_ready")

Learn more