Translate team abbreviations into logos and render these images in html tables with the 'gt' package.
Usage
gt_sdv_logos(
gt_object,
columns,
sport = c("nfl", "nba", "wnba", "mlb", "nhl", "cfb", "mbb", "wbb"),
height = 30,
locations = NULL,
include_name = FALSE,
season = NULL
)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.- sport
Character string identifying the sport.
- 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). Defaults toFALSE, the logo alone.- season
NULL(the default) for today's logos, or one season whose marks every cell shows (the ending year for the NHL). See the Historical logos section.
Historical logos
Given a season, a team is drawn with the mark it wore that season where
sdvplotR has one, and with today's logo otherwise. Coverage:
NHL: every club identity since 1917-18, primary and dark marks from the NHL's own logo catalog; a club's current era draws today's logo. Teams are keyed by the NHL triCode of that identity (
"QUE","HFD","ATL","MNS","TBL"); current clubs also answer to sdvplotR's abbreviation and full name ("TB","Tampa Bay Lightning").NFL and WNBA: relocated and defunct identities only, one mark each: NFL
"STL"(1995-2015) and"SD"(1961-2016); WNBA"HOU","SAC","CHA","DET","TUL","SAS"and"SA".No other league has per-season logos yet.
A key only finds its own identity's marks: "COL" in 1990 draws today's
Avalanche logo (the Nordiques are "QUE"), and "STL" in 2020 today's
Rams. The images are copies kept in the SportsDataverse asset archive, so
they don't change when a league reuses a file name. The NHL marks are SVG
files, which 'ggpath' reads with the 'rsvg' package. season takes single
years: the ending year for the NHL (2005 for 2004-05).
Examples
# \donttest{
library(gt)
library(sdvplotR)
teams <- valid_team_names("nfl")[1:8]
df <- data.frame(
team = teams,
logo = teams,
wins = sample(1:16, 8)
)
df |>
gt() |>
gt_sdv_logos(columns = "logo", sport = "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", sport = "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", sport = "nhl", season = 1995)
team
pts
# }









Iowa St.
St. John's (NY)