gt_merge_stack_team_color: Merge and stack text from two columns in 'gt' and color one...

gt_merge_stack_team_colorR Documentation

Merge and stack text from two columns in gt and color one with team colors

Description

The gt_merge_stack_team_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. Top text is in all caps while the lower text is bigger, bolded, and colored by the team name in another column. This is a slightly modified version of gtExtras::gt_merge_stack() written by Tom Mock.

Usage

gt_merge_stack_team_color(
  gt_object,
  col1,
  col2,
  team_col,
  font_sizes = c(12, 14),
  font_weights = c("lighter", "bold"),
  font_variants = c("small-caps"),
  color = "black"
)

Arguments

gt_object

An existing gt table object of class gt_tbl

col1

The column to stack on top.

col2

The column to merge and place below with the text team color that corresponds to team_col.

team_col

The column of team abbreviations (cleaned with clean_team_abbrs()) that match valid_team_names() for the color of the bottom text.

font_sizes

the font size for the top and bottom text in px. Can be vector of length 1 or 2. Defaults to c(12, 14)

font_weights

the font weight of the top and bottom text. Can be vector of length 1 or 2. Defaults to c("lighter", "bold")

font_variants

the font variant of the top and bottom text. Can be vector of length 1 or 2. Defaults to "small-caps"

color

The color for the top text.

Value

An object of class gt_tbl.

Examples


library(gt)
library(mlbplotR)

gt_merge_example <- mlbplotR::load_mlb_teams() %>%
  dplyr::slice(1:5) %>%
  dplyr::select(team_abbr, team_location, team_mascot) %>%
  gt::gt() %>%
  gt_merge_stack_team_color(col1 = "team_location",
                            col2 = "team_mascot",
                            team_col = "team_abbr")


camdenk/mlbplotR documentation built on Nov. 18, 2024, 10:29 p.m.