gt_merge_stack_color: Merge and stack text with background coloring from two...

View source: R/merge_and_stack.R

gt_merge_stack_colorR Documentation

Merge and stack text with background coloring from two columns in gt

Description

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

merge-stack-color.png

See Also

Other Utilities: add_text_img(), fa_icon_repeat(), fmt_pad_num(), fmt_pct_extra(), fmt_symbol_first(), generate_df(), gt_add_divider(), gt_badge(), gt_double_table(), gt_duplicate_column(), gt_fa_column(), gt_fa_rank_change(), gt_fa_rating(), gt_fa_repeats(), gt_highlight_cols(), gt_highlight_rows(), gt_img_border(), gt_img_circle(), gt_img_multi_rows(), gt_img_rows(), gt_index(), gt_merge_stack(), gt_two_column_layout(), gtsave_extra(), img_header(), pad_fn(), tab_style_by_grp()


gtExtras documentation built on Sept. 16, 2023, 1:08 a.m.