Skip to contents

This function takes a gt table and adds colored boxes as indicators for specific columns. By default, the values in the columns are assessed based on the indicator_vals argument, where the first value represents "no" (uncolored) and the second value represents "yes" (colored). Users can also define custom rules using the indicator_rule argument.

Usage

gt_indicator_boxes(
  gt_object,
  key_columns = NULL,
  indicator_vals = c(0, 1),
  indicator_rule = function(x) x == indicator_vals[2],
  color_yes = "#FCCF10",
  color_no = "#EEEEEE",
  show_na_as_na = FALSE,
  show_text = FALSE,
  show_only = NULL,
  per_column_formats = NULL,
  color_na = NULL,
  border_color = NULL,
  border_width = 0.25,
  box_width = 20,
  box_height = 20
)

Arguments

gt_object

A gt table object.

key_columns

A character vector of column names that should not be transformed. Defaults to NULL.

indicator_vals

A numeric vector of length 2 representing the "no" and "yes" values (defaults to c(0, 1)).

indicator_rule

A function that defines the rule for when the box should be colored. Defaults to checking if the value is equal to indicator_vals[2].

color_yes

A character string representing the color for "yes" indicators (default is "#FCCF10").

color_no

A character string representing the color for "no" indicators (default is "#EEEEEE").

show_na_as_na

Logical. Whether to display NA as NA (without coloring). Defaults to FALSE, which treats NA as "NO".

show_text

Logical. Whether to display the text inside the indicator boxes. Defaults to FALSE.

show_only

A character string ("yes", "no", or "NA") indicating if text should only be shown for "yes", "no", or "NA" values. Defaults to NULL (text for all values is shown).

per_column_formats

A list where each key is a column name, and each value is a list of formatting options (digits, format_type, suffix) for that column.

color_na

A character string representing the color for NA indicators. If not provided, defaults to color_no.

border_color

A character string representing the color of the border around the boxes. Defaults to NULL (no border).

border_width

Numeric. The width of the border in pixels. Defaults to 0.25.

box_width

Numeric. The default width of the box in pixels. Defaults to 20.

box_height

Numeric. The default height of the box in pixels. Defaults to 20.

Value

A modified gt table where the specified columns are replaced with HTML to display colored boxes.