Translate team abbreviations into logos and render these images in html tables with the 'gt' package.
Usage
gt_sdv_logos(
gt_object,
columns,
league,
height = 30,
locations = NULL,
include_name = FALSE,
season = NULL,
id_system = "auto",
strict = FALSE
)Arguments
- gt_object
A table object created using
gt::gt().- columns
The columns for which the image translation should be applied. Argument has no effect if
locationsis notNULL.- league
A league key from
sdv_leagues().- 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. Onlygt::cells_body(),gt::cells_stub(),gt::cells_column_labels(), andgt::cells_row_groups()helper functions can be used here.- include_name
If
TRUE, keep the cell's text after the logo, so a cell shows logo and name (what cbbplotR'sgt_cbb_teams()did), and the image gets an emptyaltso the name is not read twice. Defaults toFALSE, the logo alone, whosealtis the team's full name.- season
NULL(the default) for today's marks, or one season whose marks every cell shows (the ending year for the NHL). See the Historical logos section.- id_system, strict
How the team values are read and what an unresolved one does, as in
sdv_logo_url().
Historical logos
Given a season, a team is drawn with the mark it wore that season where
the SportsDataverse logo archive dates its marks, and with its current
mark otherwise. The season also picks the team a reused code meant then
(see sdv_resolve()). The images are copies kept in the archive, so they
don't change when a league reuses a file name. SVG marks are read with the
'rsvg' package. season takes single years: the ending year for split
seasons (2005 for 2004-05).
Examples
# \donttest{
library(gt)
library(sdvplotR)
teams <- sdv_teams("nfl")$abbr[1:8]
df <- data.frame(
team = teams,
logo = teams,
wins = sample(1:16, 8)
)
df |>
gt() |>
gt_sdv_logos(columns = "logo", league = "nfl")
team
logo
wins
# logo and name in one cell; NCAA.com school names resolve too
data.frame(team = c("Iowa St.", "St. John's (NY)"), net = c(8, 12)) |>
gt() |>
gt_sdv_logos(columns = "team", league = "mbb", height = 20, include_name = TRUE)
team
net
# the marks of the 1994-95 season
data.frame(team = c("QUE", "HFD", "WIN"), pts = c(65, 43, 39)) |>
gt() |>
gt_sdv_logos(columns = "team", league = "nhl", season = 1995)
team
pts
# }









Iowa St.
St. John's (NY)