Skip to contents

The gt_merge_stack_color() function takes an existing gt table and merges column 1 and column 2, stacking column 1's text on top of column 2's. This variant also accepts a palette argument to colorize the background values.

Usage

gt_merge_stack_color(
  gt_object,
  top_val,
  color_val,
  palette = c("#512daa", "white", "#2d6a22"),
  domain = NULL,
  small_cap = TRUE,
  font_size = c("14px", "10px"),
  font_weight = c("bold", "bold")
)

Arguments

gt_object

An existing gt table object of class gt_tbl

top_val

The column to stack on top. Will be converted to all caps, with bold text by default.

color_val

The column to merge and place below, and controls the background color value. Will be smaller by default.

palette

The colours or colour function that values will be mapped to, accepts a string or named palettes from paletteer.

domain

The possible values that can be mapped. This can be a simple numeric range (e.g. c(0, 100)).

small_cap

a logical indicating whether to use 'small-cap' on the top line of text, defaults to TRUE.

font_size

a string of length 2 indicating the font-size in px of the top and bottom text

font_weight

a string of length 2 indicating the 'font-weight' of the top and bottom text. Must be one of 'bold', 'normal', 'lighter'

Value

An object of class gt_tbl.

Examples

set.seed(12345)
 dplyr::tibble(
   value = sample(state.name, 5),
   color_by = seq.int(10, 98, length.out = 5)
 ) %>%
   gt::gt() %>%
   gt_merge_stack_color(value, color_by)

Figures