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)
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 notNULL
- height
The absolute height (px) of the image in the table cell
- locations
If
NULL
(the default), the function will render logos in argumentcolumns
. Otherwise, the cell or set of cells to be associated with the team name transformation. Only thegt::cells_body()
,gt::cells_stub()
,gt::cells_column_labels()
, andgt::cells_row_groups()
helper functions can be used here. We can enclose several of these calls within alist()
if we wish to make the transformation happen at different locations.
Examples
# \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")
# }