
Add only a binned color legend to a gt table
gtscale_color_bins.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_bins().
Usage
gtscale_color_bins(
data,
column = NULL,
palette,
domain = NULL,
bins = NULL,
transform = NULL,
oob = NULL,
right = FALSE,
labels = NULL,
title = NULL,
width = "180px",
height = "14px"
)Arguments
- data
A
gt_tblcreated bygt::gt().- column
An optional numeric, Date, POSIXt, or difftime column in the underlying table used to infer
domain.- palette
A vector of colors, palette endpoints, a single named palette, or a palette function used to color the bins.
- domain
A vector of length 2 giving the scale limits. When omitted, the limits are inferred from
column.- bins
Optional bin boundaries or a break function. When omitted, breaks are generated from
domain,column, andtransform.- transform
A transformation specification understood by
scales::as.transform(). This is used when generating default bins or when interpreting break functions.- 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 bins. When a function is supplied, it is applied to the bin 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 = currency,
method = 'bin',
palette = c('#f7fbff', '#08306b'),
bins = c(0, 10, 100, 1000, 10000000)
) |>
gtscale_color_bins(
column = currency,
palette = c('#f7fbff', '#08306b'),
bins = c(0, 10, 100, 1000, 10000000),
title = 'Binned values'
)
num
char
fctr
date
time
datetime
currency
row
group
Binned values0.4 - 1010.0 - 100100.0 - 1,0001,000.0 - 65,100