
Add only a quantile color legend to a gt table
gtscale_color_quantiles.RdThis is a lower-level helper for cases where table coloring is already
handled elsewhere. For the usual "color and legendize" workflow, prefer
gtscale_data_color_quantiles().
Usage
gtscale_color_quantiles(
data,
column,
palette,
quantiles = 4,
oob = NULL,
right = FALSE,
labels = NULL,
title = NULL,
width = "180px",
height = "14px"
)Arguments
- data
A
gt_tblcreated bygt::gt().- column
A numeric, Date, POSIXt, or difftime column in the underlying table used to infer quantile boundaries.
- palette
A vector of colors, palette endpoints, a single named palette, or a palette function used to color the quantile bins.
- quantiles
The number of quantile groups.
- oob
Out-of-bounds handling function or shortcut. Use a function like
scales::oob_squish()or a shortcut such as"censor"or"squish".- right
Whether intervals should be closed on the right. The default of
FALSEyields intervals like[a, b).- labels
An optional labeling function or a character vector for the quantile ranges. When a function is supplied, it is applied to the quantile boundaries before interval labels are constructed.
- title
Optional legend title.
- width
Width of the legend.
- height
Height of the swatches.
Value
A modified gt::gt table.
Examples
library(gt)
exibble |>
gt() |>
data_color(
columns = num,
method = 'quantile',
palette = c('#fdd49e', '#fdbb84', '#ef6548', '#990000'),
quantiles = 4
) |>
gtscale_color_quantiles(
column = num,
palette = c('#fdd49e', '#fdbb84', '#ef6548', '#990000'),
quantiles = 4,
title = 'Quantile bins'
)
num
char
fctr
date
time
datetime
currency
row
group
Quantile bins0 - 1818 - 444444 - 391,275391,275 - 8,880,000