| Title: | Color Scale Extensions for 'gt' |
|---|---|
| Description: | Adds legend helpers for color-encoded 'gt' tables. The primary interface combines 'gt::data_color()' with matched legends for continuous, binned, quantile, and discrete scales, while lower-level helpers support legend-only and reusable scale specification workflows. |
| Authors: | Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>) |
| Maintainer: | Christopher T. Kenny <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1 |
| Built: | 2026-05-16 08:59:03 UTC |
| Source: | https://github.com/christopherkenny/gtscales |
gtscales specApply only the color component of a gtscales spec
gtscale_apply(data, spec)gtscale_apply(data, spec)
data |
A |
spec |
A |
A modified gt::gt table.
gtscales spec and attach its legendApply a gtscales spec and attach its legend
gtscale_apply_legend(data, spec)gtscale_apply_legend(data, spec)
data |
A |
spec |
A |
A modified gt::gt table.
library(gt) spec <- gtscale_spec_continuous( num, palette = c('#A0442C', 'white', '#0063B1'), title = 'Value' ) exibble |> gt() |> gtscale_apply_legend(spec)library(gt) spec <- gtscale_spec_continuous( num, palette = c('#A0442C', 'white', '#0063B1'), title = 'Value' ) exibble |> gt() |> gtscale_apply_legend(spec)
gt tableThis 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().
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" )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" )
data |
A |
column |
An optional numeric, Date, POSIXt, or difftime column in the
underlying table used to infer |
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 |
bins |
Optional bin boundaries or a break function. When omitted,
breaks are generated from |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
right |
Whether intervals should be closed on the right. The default of
|
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. |
A modified gt::gt table.
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' )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' )
gt tableThis 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_continuous().
gtscale_color_continuous( data, column = NULL, palette = NULL, domain = NULL, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", fn = NULL )gtscale_color_continuous( data, column = NULL, palette = NULL, domain = NULL, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", fn = NULL )
data |
A |
column |
An optional numeric column in the underlying table used to infer
|
palette |
A vector of colors used in the legend gradient. A single named palette or palette function can also be supplied. |
domain |
A numeric vector of length 2 giving the scale limits. When
omitted, the limits are inferred from |
breaks |
Optional break values or a break function to display below the gradient. |
labels |
An optional labeling function or a character vector for the breaks. |
title |
Optional legend title. |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
direction |
CSS gradient direction. Defaults to |
width |
Width of the legend bar. |
height |
Height of the legend bar. |
fn |
Backward-compatible fallback for passing a |
A modified gt::gt table.
library(gt) exibble |> gt() |> data_color( columns = num, method = 'numeric', palette = c('#A0442C', 'white', '#0063B1') ) |> gtscale_color_continuous( column = num, palette = c('#A0442C', 'white', '#0063B1'), title = 'Value' )library(gt) exibble |> gt() |> data_color( columns = num, method = 'numeric', palette = c('#A0442C', 'white', '#0063B1') ) |> gtscale_color_continuous( column = num, palette = c('#A0442C', 'white', '#0063B1'), title = 'Value' )
gt tableThis 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_discrete().
gtscale_color_discrete( data, values, labels = values, title = NULL, swatch_size = "12px" )gtscale_color_discrete( data, values, labels = values, title = NULL, swatch_size = "12px" )
data |
A |
values |
A vector of color values or a single named discrete palette. |
labels |
Labels for each color swatch. Defaults to |
title |
Optional legend title. |
swatch_size |
Size of each discrete color swatch. |
A modified gt::gt table.
library(gt) data.frame( category = c('Low', 'Medium', 'High'), value = c(12, 47, 83) ) |> gt() |> data_color( columns = category, method = 'factor', palette = c('#1b9e77', '#d95f02', '#7570b3') ) |> gtscale_color_discrete( values = c('#1b9e77', '#d95f02', '#7570b3'), labels = c('Low', 'Medium', 'High'), title = 'Category' )library(gt) data.frame( category = c('Low', 'Medium', 'High'), value = c(12, 47, 83) ) |> gt() |> data_color( columns = category, method = 'factor', palette = c('#1b9e77', '#d95f02', '#7570b3') ) |> gtscale_color_discrete( values = c('#1b9e77', '#d95f02', '#7570b3'), labels = c('Low', 'Medium', 'High'), title = 'Category' )
gt tableThis 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_diverging().
gtscale_color_diverging( data, column = NULL, palette, domain = NULL, midpoint = 0, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", mid_color = "#FFFFFF" )gtscale_color_diverging( data, column = NULL, palette, domain = NULL, midpoint = 0, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", mid_color = "#FFFFFF" )
data |
A |
column |
An optional numeric column or shared set of numeric columns in
the underlying table used to infer |
palette |
Two endpoint colors, three diverging colors, or a single named palette. |
domain |
A numeric vector of length 2 giving the scale limits. When
omitted, the limits are inferred from |
midpoint |
Numeric midpoint used to anchor the diverging scale. |
breaks |
Optional break values or a break function to display below the gradient. |
labels |
An optional labeling function or a character vector for the breaks. |
title |
Optional legend title. |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
direction |
CSS gradient direction. Defaults to |
width |
Width of the legend bar. |
height |
Height of the legend bar. |
mid_color |
Midpoint color when |
A modified gt::gt table.
gt tableThis 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().
gtscale_color_quantiles( data, column, palette, quantiles = 4, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px" )gtscale_color_quantiles( data, column, palette, quantiles = 4, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px" )
data |
A |
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
|
right |
Whether intervals should be closed on the right. The default of
|
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. |
A modified gt::gt table.
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' )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' )
gt column and add a matching binned legendThis is the primary interface for binned scales in gtscales.
gtscale_data_color_bins( data, column, palette, bins = NULL, domain = NULL, transform = NULL, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000" )gtscale_data_color_bins( data, column, palette, bins = NULL, domain = NULL, transform = NULL, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000" )
data |
A |
column |
A numeric, Date, POSIXt, or difftime column to color and legendize. |
palette |
A vector of colors, palette endpoints, a single named palette, or a palette function used for the bins. |
bins |
Optional bin boundaries or a break function. When omitted,
breaks are generated from |
domain |
A vector of length 2 giving the scale limits. When omitted,
the limits are inferred from |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
right |
Whether intervals should be closed on the right. The default of
|
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. |
apply_to |
Whether colors should be applied to cell fill or text. |
na_color |
Color used for missing values. |
alpha |
Alpha applied by |
reverse |
Whether to reverse the color mapping. |
autocolor_text |
Whether to automatically adjust text color. |
contrast_algo |
Contrast algorithm passed to |
autocolor_light |
Light text color used by |
autocolor_dark |
Dark text color used by |
A modified gt::gt table.
library(gt) exibble |> gt() |> gtscale_data_color_bins( column = currency, palette = c('#f7fbff', '#08306b'), bins = c(0, 10, 100, 1000, 10000, 70000), title = 'Currency bins' )library(gt) exibble |> gt() |> gtscale_data_color_bins( column = currency, palette = c('#f7fbff', '#08306b'), bins = c(0, 10, 100, 1000, 10000, 70000), title = 'Currency bins' )
gt column and add a matching continuous legendThis is the primary interface for continuous scales in gtscales.
gtscale_data_color_continuous( data, column, palette = NULL, domain = NULL, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000", fn = NULL )gtscale_data_color_continuous( data, column, palette = NULL, domain = NULL, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000", fn = NULL )
data |
A |
column |
A numeric column to color and legendize. |
palette |
A vector of colors used in the table and legend gradient. A single named palette or palette function can also be supplied. |
domain |
A numeric vector of length 2 giving the scale limits. When
omitted, the limits are inferred from |
breaks |
Optional break values or a break function to display below the gradient. |
labels |
An optional labeling function or a character vector for the breaks. |
title |
Optional legend title. |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
direction |
CSS gradient direction. Defaults to |
width |
Width of the legend bar. |
height |
Height of the legend bar. |
apply_to |
Whether colors should be applied to cell fill or text. |
na_color |
Color used for missing values. |
alpha |
Alpha applied by |
reverse |
Whether to reverse the color mapping. |
autocolor_text |
Whether to automatically adjust text color. |
contrast_algo |
Contrast algorithm passed to |
autocolor_light |
Light text color used by |
autocolor_dark |
Dark text color used by |
fn |
Optional |
A modified gt::gt table.
library(gt) exibble |> gt() |> gtscale_data_color_continuous( column = num, palette = c('#A0442C', 'white', '#0063B1'), title = 'Value' )library(gt) exibble |> gt() |> gtscale_data_color_continuous( column = num, palette = c('#A0442C', 'white', '#0063B1'), title = 'Value' )
gt column and add a matching discrete legendThis is the primary interface for discrete scales in gtscales.
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" )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" )
data |
A |
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 |
title |
Optional legend title. |
swatch_size |
Size of each discrete color swatch. |
levels |
Optional factor levels passed to |
ordered |
Whether the scale should be treated as ordered. |
na_color |
Color used for missing values. |
alpha |
Alpha applied by |
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 |
autocolor_light |
Light text color used by |
autocolor_dark |
Dark text color used by |
A modified gt::gt table.
library(gt) data.frame( category = c('Low', 'Medium', 'High'), value = c(12, 47, 83) ) |> gt() |> gtscale_data_color_discrete( column = category, values = c('#1b9e77', '#d95f02', '#7570b3'), labels = c('Low', 'Medium', 'High'), title = 'Category' )library(gt) data.frame( category = c('Low', 'Medium', 'High'), value = c(12, 47, 83) ) |> gt() |> gtscale_data_color_discrete( column = category, values = c('#1b9e77', '#d95f02', '#7570b3'), labels = c('Low', 'Medium', 'High'), title = 'Category' )
gt column with a diverging scale and add a matching legendThis is the primary interface for midpoint-aware diverging scales in
gtscales.
gtscale_data_color_diverging( data, column, palette, domain = NULL, midpoint = 0, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000", mid_color = "#FFFFFF" )gtscale_data_color_diverging( data, column, palette, domain = NULL, midpoint = 0, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000", mid_color = "#FFFFFF" )
data |
A |
column |
A numeric column or shared set of numeric columns to color and legendize. |
palette |
Two endpoint colors, three diverging colors, or a single named palette. |
domain |
A numeric vector of length 2 giving the scale limits. When
omitted, the limits are inferred from |
midpoint |
Numeric midpoint used to anchor the diverging scale. |
breaks |
Optional break values or a break function to display below the gradient. |
labels |
An optional labeling function or a character vector for the breaks. |
title |
Optional legend title. |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
direction |
CSS gradient direction. Defaults to |
width |
Width of the legend bar. |
height |
Height of the legend bar. |
apply_to |
Whether colors should be applied to cell fill or text. |
na_color |
Color used for missing values. |
alpha |
Alpha applied by |
reverse |
Whether to reverse the color mapping. |
autocolor_text |
Whether to automatically adjust text color. |
contrast_algo |
Contrast algorithm passed to |
autocolor_light |
Light text color used by |
autocolor_dark |
Dark text color used by |
mid_color |
Midpoint color when |
A modified gt::gt table.
gt column and add a matching quantile legendThis is the primary interface for quantile scales in gtscales.
gtscale_data_color_quantiles( data, column, palette, quantiles = 4, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000" )gtscale_data_color_quantiles( data, column, palette, quantiles = 4, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px", apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000" )
data |
A |
column |
A numeric, Date, POSIXt, or difftime column to color and legendize. |
palette |
A vector of colors, palette endpoints, a single named palette, or a palette function used for the quantile groups. |
quantiles |
The number of quantile groups. |
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
right |
Whether intervals should be closed on the right. The default of
|
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. |
apply_to |
Whether colors should be applied to cell fill or text. |
na_color |
Color used for missing values. |
alpha |
Alpha applied by |
reverse |
Whether to reverse the color mapping. |
autocolor_text |
Whether to automatically adjust text color. |
contrast_algo |
Contrast algorithm passed to |
autocolor_light |
Light text color used by |
autocolor_dark |
Dark text color used by |
A modified gt::gt table.
library(gt) exibble |> gt() |> gtscale_data_color_quantiles( column = num, palette = c('#fdd49e', '#fdbb84', '#ef6548', '#990000'), quantiles = 4, title = 'Quantile bins' )library(gt) exibble |> gt() |> gtscale_data_color_quantiles( column = num, palette = c('#fdd49e', '#fdbb84', '#ef6548', '#990000'), quantiles = 4, title = 'Quantile bins' )
gtscales specAttach only the legend component of a gtscales spec
gtscale_legend(data, spec)gtscale_legend(data, spec)
data |
A |
spec |
A |
A modified gt::gt table.
gtscale_spec
Render a legend from a gtscale_spec
gtscale_render_legend( spec, data = NULL, output = c("contextual", "html", "latex", "rtf", "word", "typst") )gtscale_render_legend( spec, data = NULL, output = c("contextual", "html", "latex", "rtf", "word", "typst") )
spec |
A |
data |
An optional |
output |
Output target. Use |
Rendered legend content for the requested output target.
spec <- gtscale_spec_quantiles( num, palette = c('#fdd49e', '#fdbb84', '#ef6548', '#990000'), quantiles = 4, title = 'Quartiles' ) gtscale_render_legend( spec = spec, data = gt::gt(gt::exibble), output = 'latex' )spec <- gtscale_spec_quantiles( num, palette = c('#fdd49e', '#fdbb84', '#ef6548', '#990000'), quantiles = 4, title = 'Quartiles' ) gtscale_render_legend( spec = spec, data = gt::gt(gt::exibble), output = 'latex' )
gtscales specCreate a binned gtscales spec
gtscale_spec_bins( column, palette, bins = NULL, domain = NULL, transform = NULL, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px" )gtscale_spec_bins( column, palette, bins = NULL, domain = NULL, transform = NULL, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px" )
column |
A column to target. |
palette |
A vector of colors or palette endpoints used for the bins. A single named palette or palette function can also be supplied. |
bins |
Optional bin boundaries or a break function. When omitted,
breaks are generated from the |
domain |
Optional limits. If omitted, these can be inferred when the
spec is applied to a |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
right |
Whether intervals should be closed on the right. The default of
|
labels |
An optional labeling function or character vector for the legend. When omitted, labels are inferred from the bin values. |
title |
Optional legend title. |
width |
Width of the legend. |
height |
Height of the swatches. |
A gtscale_spec.
gtscales specCreate a continuous gtscales spec
gtscale_spec_continuous( column, palette = NULL, domain = NULL, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", fn = NULL )gtscale_spec_continuous( column, palette = NULL, domain = NULL, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", fn = NULL )
column |
A column to target. |
palette |
A vector of colors used in the scale.
A single named palette such as |
domain |
Optional numeric limits. If omitted, these can be inferred when
the spec is applied to a |
breaks |
Optional break values or a break function for the legend. |
labels |
An optional labeling function or character vector for the legend. When omitted, labels are inferred from the data or transform. |
title |
Optional legend title. |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut passed through to the
internal color mapper. Use a function like |
direction |
CSS gradient direction. Defaults to |
width |
Width of the legend bar. |
height |
Height of the legend bar. |
fn |
Optional |
A gtscale_spec.
gtscales specCreate a discrete gtscales spec
gtscale_spec_discrete( column, values, labels = values, title = NULL, swatch_size = "12px", levels = NULL, ordered = FALSE )gtscale_spec_discrete( column, values, labels = values, title = NULL, swatch_size = "12px", levels = NULL, ordered = FALSE )
column |
A column to target. |
values |
A vector of color values, a single named discrete palette, or a discrete palette function. |
labels |
Labels for each legend swatch. Defaults to |
title |
Optional legend title. |
swatch_size |
Size of each discrete color swatch. |
levels |
Optional factor levels. |
ordered |
Whether the scale should be treated as ordered. |
A gtscale_spec.
gtscales specCreate a diverging gtscales spec
gtscale_spec_diverging( column, palette, domain = NULL, midpoint = 0, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", mid_color = "#FFFFFF" )gtscale_spec_diverging( column, palette, domain = NULL, midpoint = 0, breaks = NULL, labels = NULL, title = NULL, transform = NULL, oob = NULL, direction = "to right", width = "160px", height = "14px", mid_color = "#FFFFFF" )
column |
A column or shared set of columns to target. |
palette |
Two endpoint colors or three diverging colors.
A single named palette such as |
domain |
Optional numeric limits. If omitted, these can be inferred when
the spec is applied to a |
midpoint |
Numeric midpoint used to anchor the diverging scale. |
breaks |
Optional break values or a break function for the legend. |
labels |
An optional labeling function or character vector for the legend. When omitted, labels are inferred from the data or transform. |
title |
Optional legend title. |
transform |
A transformation specification understood by
|
oob |
Out-of-bounds handling function or shortcut passed through to the
internal color mapper. Use a function like |
direction |
CSS gradient direction. Defaults to |
width |
Width of the legend bar. |
height |
Height of the legend bar. |
mid_color |
Midpoint color when |
A gtscale_spec.
gtscales specCreate a quantile gtscales spec
gtscale_spec_quantiles( column, palette, quantiles = 4, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px" )gtscale_spec_quantiles( column, palette, quantiles = 4, oob = NULL, right = FALSE, labels = NULL, title = NULL, width = "180px", height = "14px" )
column |
A numeric, Date, POSIXt, or difftime column to target. |
palette |
A vector of colors or palette endpoints used for the quantile groups. A single named palette or palette function can also be supplied. |
quantiles |
The number of quantile groups. |
oob |
Out-of-bounds handling function or shortcut. Use a function like
|
right |
Whether intervals should be closed on the right. The default of
|
labels |
An optional labeling function or character vector for the legend. When omitted, labels are inferred from the quantile break values. |
title |
Optional legend title. |
width |
Width of the legend. |
height |
Height of the swatches. |
A gtscale_spec.
gtscales spec is appliedSet how a gtscales spec is applied
gtscale_spec_set_application( spec, apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000" )gtscale_spec_set_application( spec, apply_to = c("fill", "text"), na_color = NULL, alpha = NULL, reverse = FALSE, autocolor_text = TRUE, contrast_algo = c("apca", "wcag"), autocolor_light = "#FFFFFF", autocolor_dark = "#000000" )
spec |
A |
apply_to |
Whether colors should be applied to cell fill or text. |
na_color |
Color used for missing values. |
alpha |
Alpha applied by |
reverse |
Whether to reverse the color mapping. |
autocolor_text |
Whether to automatically adjust text color. |
contrast_algo |
Contrast algorithm passed to |
autocolor_light |
Light text color used by |
autocolor_dark |
Dark text color used by |
A modified gtscale_spec.
gtscales legend should be renderedSet how a gtscales legend should be rendered
gtscale_spec_set_legend( spec, output = "contextual", placement = "source_note", layout = c("stack", "inline"), align = c("left", "center", "right"), show_border = TRUE, border_color = "#D0D7DE", border_radius = "8px", show_na = FALSE, na_label = "Missing", na_color = NULL )gtscale_spec_set_legend( spec, output = "contextual", placement = "source_note", layout = c("stack", "inline"), align = c("left", "center", "right"), show_border = TRUE, border_color = "#D0D7DE", border_radius = "8px", show_na = FALSE, na_label = "Missing", na_color = NULL )
spec |
A |
output |
Output target for the legend. Use |
placement |
Legend placement target. |
layout |
Whether multiple legends in the same heading area should stack vertically or sit inline. |
align |
Horizontal alignment for the legend container. |
show_border |
Whether the legend bar, bin frame, and swatches should draw borders. |
border_color |
Border color used for legend frames and swatches. |
border_radius |
Border radius used for HTML and Typst legend frames. |
show_na |
Whether to include an explicit missing-value legend entry. |
na_label |
Label to use for missing values in the legend. |
na_color |
Optional legend swatch color for missing values. When
omitted and |
A modified gtscale_spec.