Skip to contents

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 locations is not NULL.

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 argument columns. Otherwise, the cell or set of cells to be associated with the team name transformation. Only gt::cells_body(), gt::cells_stub(), gt::cells_column_labels(), and gt::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's gt_cbb_teams() did). Defaults to FALSE, 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.

Value

An object of class gt_tbl.

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 wins
ARI The ARI logo 1
ATL The ATL logo 3
BAL The BAL logo 15
BUF The BUF logo 10
CAR The CAR logo 9
CHI The CHI logo 5
CIN The CIN logo 8
CLE The CLE logo 14
# 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 ISU logoIowa St. 8
The SJU logoSt. John's (NY) 12
# 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
The COL logo 65
The CAR logo 43
The WPG logo 39
# }