gt_merge_stack: Merge and stack text from two columns in 'gt'

View source: R/merge_and_stack.R

gt_merge_stackR Documentation

Merge and stack text from two columns in gt

Description

The gt_merge_stack() function takes an existing gt table and merges column 1 and column 2, stacking column 1's text on top of column 2's. Top text is in all caps with black bold text, while the lower text is smaller and dark grey.

Usage

gt_merge_stack(
  gt_object,
  col1,
  col2,
  palette = c("black", "grey"),
  ...,
  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

col1

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

col2

The column to merge and place below. Will be smaller and dark grey.

palette

The colors for the text, where the first color is the top , ie col1 and the second color is the bottom, ie col2. Defaults to c("black","grey"). For more information on built-in color names, see colors().

...

Arguments passed on to scales::col2hcl

h

Hue, ⁠[0, 360]⁠

c

Chroma, ⁠[0, 100]⁠

l

Luminance, ⁠[0, 100]⁠

alpha

Alpha, ⁠[0, 1]⁠.

small_cap

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

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

library(gt)
teams <- "https://github.com/nflverse/nflfastR-data/raw/master/teams_colors_logos.rds"
team_df <- readRDS(url(teams))

stacked_tab <- team_df %>%
 dplyr::select(team_nick, team_abbr, team_conf, team_division, team_wordmark) %>%
 head(8) %>%
 gt(groupname_col = "team_conf") %>%
 gt_merge_stack(col1 = team_nick, col2 = team_division) %>%
 gt_img_rows(team_wordmark)

Figures

merge-stack.png

Function ID

2-6

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_color(), 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.