Translate NFL player gsis IDs to player headshots and render these images in html tables with the 'gt' package.
Arguments
- gt_object
A table object that is created using the
gt::gt()
function.- columns
The columns for which the image translation should be applied. Argument 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/wordmarks 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.
See also
The logo and wordmark rendering functions gt_nfl_logos()
and
gt_nfl_wordmarks()
.
Examples
# \donttest{
library(nflplotR)
library(gt)
# Silence an nflreadr message that is irrelevant here
old <- options(nflreadr.cache_warning = FALSE)
df <- data.frame(
player_gsis = c("00-0033873",
"00-0026498",
"00-0035228",
"00-0031237",
"00-0036355",
"00-0019596",
"00-0033077",
"00-0012345",
"00-0031280"),
player_name = c("P.Mahomes",
"M.Stafford",
"K.Murray",
"T.Bridgewater",
"J.Herbert",
"T.Brady",
"D.Prescott",
"Non.Match",
"D.Carr")
)
# Replace player IDs with headshot images
table <- gt(df) %>%
gt_nfl_headshots("player_gsis")
# Restore old options
options(old)
# }