Skip to contents

The gt_fmt_mlb_logo, gt_fmt_mlb_scoreboard_logo, and gt_fmt_mlb_dot_logo functions take an existing gt_tbl object and converts MLB team names from valid_team_names() into team logos. 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_logo(gt_object, columns, height = 30, locations = NULL)

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

gt_fmt_mlb_dot_logo(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. Argument 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.

Value

An object of class gt_tbl.

Examples

library(gt)
library(mlbplotR)

df <- data.frame(team = valid_team_names()[1:5],
                 logo = valid_team_names()[1:5],
                 scoreboard_logo = valid_team_names()[1:5],
                 dot_logo = valid_team_names()[1:5])

gt_logo_example <- df %>%
 gt::gt() %>%
 gt_fmt_mlb_logo(columns = "logo") %>%
 gt_fmt_mlb_scoreboard_logo(columns = "scoreboard_logo") %>%
 gt_fmt_mlb_dot_logo(columns = "dot_logo")