Learn R Programming

mlbplotR (version 1.2.0)

gt_mlb_headshots: Render Player Headshots in 'gt' Tables

Description

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, locations = NULL)

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

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

Value

An object of class gt_tbl.

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

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.

Examples

Run this code
# \donttest{
library(gt)
library(mlbplotR)
gt_headshot_example <- data.frame(
  player_name = c(
    "Nathan Eovaldi", "Marcus Semien", "Corey Seager", "Jacob deGrom", "Chris Martin"
  ),
  savant_id1 = c(543135, 543760, 608369, 594798, 455119),
  savant_id2 = c(543135, 543760, 608369, 594798, 455119)
  ) %>%
  gt::gt() %>%
  gt_fmt_mlb_headshot(columns = "savant_id1") %>%
  gt_fmt_mlb_dot_headshot(columns = "savant_id2")
# }

Run the code above in your browser using DataLab