Skip to contents

gt_fmt_mlb_headshot, gt_fmt_mlb_dot_headshot, and gt_fmt_milb_dot_headshot take an existing gt_tbl object and converts player ids into headshots. This is a wrapper around gtExtras::gt_image_rows() written by Tom Mock, which is a wrapper around gt::text_transform() + gt::web_image()/ gt::local_image() with the necessary boilerplate already applied.

Usage

gt_fmt_mlb_headshot(
  gt_object,
  columns,
  height = 30,
  na_headshot_to_logo = TRUE,
  locations = NULL
)

gt_fmt_mlb_dot_headshot(
  gt_object,
  columns,
  height = 30,
  na_headshot_to_logo = TRUE,
  locations = NULL
)

gt_fmt_milb_dot_headshot(
  gt_object,
  columns,
  height = 30,
  na_headshot_to_logo = TRUE,
  locations = NULL
)

Arguments

gt_object

An existing gt table object of class gt_tbl

columns

The columns wherein changes to cell data colors should occur. Has no effect if locations is not NULL

height

The absolute height (px) of the image in the table cell

should NA/non matches return the MLB logo instead of a grayed out blank headshot? Only has an effect with gt_fmt_mlb_headshot. Defaults to TRUE

locations

If NULL (the default), the function will render logos in argument columns. Otherwise, the cell or set of cells to be associated with the team name transformation. Only the gt::cells_body(), gt::cells_stub(), gt::cells_column_labels(), and gt::cells_row_groups() helper functions can be used here. We can enclose several of these calls within a list() if we wish to make the transformation happen at different locations.

Value

An object of class gt_tbl.

Examples

# \donttest{
library(gt)
library(mlbplotR)
gt_headshot_example <- mlbplotR::load_headshots() %>%
  head(5) %>%
  dplyr::select(player_name, savant_id1 = savant_id, savant_id2 = savant_id) %>%
  gt::gt() %>%
  gt_fmt_mlb_headshot(columns = "savant_id1") %>%
  gt_fmt_mlb_dot_headshot(columns = "savant_id2")
# }