The gt_fmt_milb_logo and gt_fmt_milb_dot_logo functions take an existing
gt_tbl object and converts MiLB 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_milb_logo(gt_object, columns, height = 30, locations = NULL)
gt_fmt_milb_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
locationsis 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_milb_example <- mlbplotR::load_milb_teams() %>%
dplyr::filter(parent_org_name == "Texas Rangers") %>%
dplyr::mutate(dot = team_name) %>%
dplyr::select(team_name, dot, team_location, team_mascot) %>%
gt::gt() %>%
gt_fmt_milb_logo(columns = "team_name") %>%
gt_fmt_milb_dot_logo(columns = "dot")
# }
