
Color a categorical gt column and add a matching discrete legend
gtscale_data_color_discrete.RdThis is the primary interface for discrete scales in gtscales.
Usage
gtscale_data_color_discrete(
data,
column,
values,
labels = values,
title = NULL,
swatch_size = "12px",
levels = NULL,
ordered = FALSE,
na_color = NULL,
alpha = NULL,
reverse = FALSE,
apply_to = c("fill", "text"),
autocolor_text = TRUE,
contrast_algo = c("apca", "wcag"),
autocolor_light = "#FFFFFF",
autocolor_dark = "#000000"
)Arguments
- data
A
gt_tblcreated bygt::gt().- column
A categorical column to color and legendize.
- values
A vector of color values or a single named discrete palette used in the table and legend.
- labels
Labels for each color swatch. Defaults to
values.- title
Optional legend title.
- swatch_size
Size of each discrete color swatch.
- levels
Optional factor levels passed to
gt::data_color().- ordered
Whether the scale should be treated as ordered.
- na_color
Color used for missing values.
- alpha
Alpha applied by
gt::data_color().- reverse
Whether to reverse the color mapping.
- apply_to
Whether colors should be applied to cell fill or text.
- autocolor_text
Whether to automatically adjust text color.
- contrast_algo
Contrast algorithm passed to
gt::data_color().- autocolor_light
Light text color used by
gt::data_color().- autocolor_dark
Dark text color used by
gt::data_color().
Value
A modified gt::gt table.