This function adds color pills to a specified column in a gt table, allowing
the column's values to be filled with color based on ordinal ranking or continuous
values. You can provide a custom domain and palette, with optional paletteer support.
Usage
gt_color_pills(
gt_object,
columns,
palette = c("#C84630", "#5DA271"),
fill_type = "continuous",
rank_order = "desc",
digits = NULL,
domain = NULL,
format_type = "number",
scale_percent = TRUE,
suffix = "",
reverse = FALSE,
outline_color = NULL,
outline_width = 0.25,
pal_type = "discrete",
pill_height = 25,
...
)Arguments
- gt_object
A
gttable object to modify.- columns
A column or set of columns within the
gttable to apply the color pills.- palette
A color palette to use. If you want to use a palette from
paletteer, specify the palette aspackage::palette. Defaults toc("#C84630", "#5DA271").- fill_type
Character. Either
"rank"or"continuous", determining whether to fill based on ordinal rank or continuous values.- rank_order
Character. Either
"asc"or"desc", used whenfill_typeis"rank". Defaults to"desc".- digits
Integer. The number of decimal places to round the values to. Defaults to
NULL.- domain
A numeric vector specifying the domain for continuous color scaling. If
NULL, the domain will be automatically determined from the data. Defaults toNULL.- format_type
Character. The format of the values in the column. Options are
"number","comma","currency", or"percent". Defaults to"number".- scale_percent
Logical. Should the values be scaled to percent (multiplied by 100)? Defaults to
TRUE.- suffix
Optional. A character string to append as a suffix to the formatted value (e.g., "M", "K", "lbs"). Defaults to
"".- reverse
Logical. Should the color palette be reversed? Defaults to
FALSE.- outline_color
Optional. A hex color code for the border around the pills. Defaults to
NULL.- outline_width
Numeric. The width of the border around the pills in pixels. Defaults to
0.25.- pal_type
Character. Either
"discrete"or"continuous", used when applyingpaletteerpalettes. Defaults to"discrete".- pill_height
Numeric. The height of each color pill in pixels. Defaults to
25.- ...
Additional arguments passed to
scales::col_numeric.
