Super Bowl Champions: Analysis Using the gt R Package

sports
analysis
code
data wrangling
R
data visualization
Explore the Super Bowl champions’ table, highlighting winners, scores, and locations, using the gt R package. Uncover your team’s success!
Published

February 13, 2023

In celebration of the 2023 Super Bowl, I explored the gt R package to analyze the historical data of teams that emerged victorious since the inaugural Super Bowl. Using gt, I created a comprehensive table that presents an overview of Super Bowl champions throughout the years.

To begin, I loaded the necessary packages and imported the Super Bowl dataset. I also incorporated team logos into the table for enhanced visual appeal.

With the flexibility of the gt package, I curated and formatted the table columns, highlighting essential information such as the Super Bowl number, date, winning and losing teams, points scored, and the event’s location. This table serves as a valuable resource for gaining insights into the historical context and achievements of each Super Bowl.

Look at the code
# load packages and read in data
library(tidyverse)
library(gt)
library(lubridate)

superbowls <- readr::read_csv('~/Desktop/quarto-portfolio/posts/Super_Bowl.csv')
 
# add logos for each team
superbowls <- superbowls %>% 
  mutate(win_logo_url = 
  case_when(
          Winner == "Green Bay Packers" ~ "https://upload.wikimedia.org/wikipedia/commons/5/50/Green_Bay_Packers_logo.svg",
          Winner == "New York Jets" ~ "https://upload.wikimedia.org/wikipedia/en/6/6b/New_York_Jets_logo.svg",
          Winner == "Kansas City Chiefs" ~ "https://upload.wikimedia.org/wikipedia/en/e/e1/Kansas_City_Chiefs_logo.svg",
          Winner == "Baltimore Colts" ~ "https://upload.wikimedia.org/wikipedia/en/1/1f/Baltimore_Colts_logo_1961-1978.gif",
          Winner == "Dallas Cowboys" ~ "https://upload.wikimedia.org/wikipedia/commons/1/15/Dallas_Cowboys.svg",
          Winner == "Miami Dolphins" ~ "https://upload.wikimedia.org/wikipedia/en/3/37/Miami_Dolphins_logo.svg",
          Winner == "Pittsburgh Steelers" ~ "https://upload.wikimedia.org/wikipedia/commons/d/de/Pittsburgh_Steelers_logo.svg",
          Winner == "Oakland Raiders" ~ "https://upload.wikimedia.org/wikipedia/en/4/48/Las_Vegas_Raiders_logo.svg",
          Winner == "Los Angeles Raiders" ~ "https://upload.wikimedia.org/wikipedia/en/4/48/Las_Vegas_Raiders_logo.svg",
          Winner == "San Francisco 49ers" ~ "https://upload.wikimedia.org/wikipedia/commons/3/3a/San_Francisco_49ers_logo.svg",
          Winner == "Washington Redskins" ~ "https://e7.pngegg.com/pngimages/193/260/png-clipart-redskins-logo-red-skins-logo-sports-nfl-football.png",
          Winner == "Chicago Bears" ~ "https://upload.wikimedia.org/wikipedia/commons/5/5c/Chicago_Bears_logo.svg",
          Winner == "New York Giants" ~ "https://upload.wikimedia.org/wikipedia/commons/6/60/New_York_Giants_logo.svg",
          Winner == "Denver Broncos" ~ "https://upload.wikimedia.org/wikipedia/en/4/44/Denver_Broncos_logo.svg",
          Winner == "St. Louis Rams" ~ "https://upload.wikimedia.org/wikipedia/en/8/8b/NFL_Rams_logo.svg",
          Winner == "Baltimore Ravens" ~ "https://upload.wikimedia.org/wikipedia/en/1/16/Baltimore_Ravens_logo.svg",
          Winner == "New England Patriots" ~ "https://upload.wikimedia.org/wikipedia/en/b/b9/New_England_Patriots_logo.svg",
          Winner == "Tampa Bay Buccaneers" ~ "https://upload.wikimedia.org/wikipedia/en/a/a2/Tampa_Bay_Buccaneers_logo.svg",
          Winner == "Indianapolis Colts" ~ "https://upload.wikimedia.org/wikipedia/commons/0/00/Indianapolis_Colts_logo.svg",
          Winner == "New Orleans Saints" ~ "https://upload.wikimedia.org/wikipedia/commons/5/50/New_Orleans_Saints_logo.svg",
          Winner == "Seattle Seahawks" ~ "https://upload.wikimedia.org/wikipedia/en/8/8e/Seattle_Seahawks_logo.svg",
          Winner == "Philadelphia Eagles" ~ "https://upload.wikimedia.org/wikipedia/en/8/8e/Philadelphia_Eagles_logo.svg"
          )
       ) %>% 
  mutate(lose_logo_url = 
  case_when(
          Loser == "Green Bay Packers" ~ "https://upload.wikimedia.org/wikipedia/commons/5/50/Green_Bay_Packers_logo.svg",
            Loser == "Minnesota Vikings" ~ "https://upload.wikimedia.org/wikipedia/en/4/48/Minnesota_Vikings_logo.svg",
          Loser == "Kansas City Chiefs" ~ "https://upload.wikimedia.org/wikipedia/en/e/e1/Kansas_City_Chiefs_logo.svg",
          Loser == "Baltimore Colts" ~ "https://upload.wikimedia.org/wikipedia/en/1/1f/Baltimore_Colts_logo_1961-1978.gif",
          Loser == "Dallas Cowboys" ~ "https://upload.wikimedia.org/wikipedia/commons/1/15/Dallas_Cowboys.svg",
          Loser == "Miami Dolphins" ~ "https://upload.wikimedia.org/wikipedia/en/3/37/Miami_Dolphins_logo.svg",
          Loser == "Pittsburgh Steelers" ~ "https://upload.wikimedia.org/wikipedia/commons/d/de/Pittsburgh_Steelers_logo.svg",
          Loser == "Oakland Raiders" ~ "https://upload.wikimedia.org/wikipedia/en/4/48/Las_Vegas_Raiders_logo.svg",
          Loser == "Los Angeles Rams" ~ "https://upload.wikimedia.org/wikipedia/en/8/8a/Los_Angeles_Rams_logo.svg",
          Loser == "San Francisco 49ers" ~ "https://upload.wikimedia.org/wikipedia/commons/3/3a/San_Francisco_49ers_logo.svg",
          Loser == "Washington Redskins" ~ "https://e7.pngegg.com/pngimages/193/260/png-clipart-redskins-logo-red-skins-logo-sports-nfl-football.png",
          Loser == "Chicago Bears" ~ "https://upload.wikimedia.org/wikipedia/commons/5/5c/Chicago_Bears_logo.svg",
          Loser == "New York Giants" ~ "https://upload.wikimedia.org/wikipedia/commons/6/60/New_York_Giants_logo.svg",
          Loser == "Denver Broncos" ~ "https://upload.wikimedia.org/wikipedia/en/4/44/Denver_Broncos_logo.svg",
          Loser == "St. Louis Rams" ~ "https://upload.wikimedia.org/wikipedia/en/8/8b/NFL_Rams_logo.svg",
           Loser == "Cincinnati Bengals" ~ "https://upload.wikimedia.org/wikipedia/commons/8/81/Cincinnati_Bengals_logo.svg",
          Loser == "New England Patriots" ~ "https://upload.wikimedia.org/wikipedia/en/b/b9/New_England_Patriots_logo.svg",
           Loser == "Buffalo Bills" ~ "https://upload.wikimedia.org/wikipedia/en/7/77/Buffalo_Bills_logo.svg",
          Loser == "Indianapolis Colts" ~ "https://upload.wikimedia.org/wikipedia/commons/0/00/Indianapolis_Colts_logo.svg",
           Loser == "San Diego Chargers" ~ "https://upload.wikimedia.org/wikipedia/en/7/72/NFL_Chargers_logo.svg",
          Loser == "Seattle Seahawks" ~ "https://upload.wikimedia.org/wikipedia/en/8/8e/Seattle_Seahawks_logo.svg",
          Loser == "Philadelphia Eagles" ~ "https://upload.wikimedia.org/wikipedia/en/8/8e/Philadelphia_Eagles_logo.svg",
          Loser == "Atlanta Falcons" ~ "https://upload.wikimedia.org/wikipedia/en/c/c5/Atlanta_Falcons_logo.svg",
          Loser == "Tennessee Titans" ~ "https://upload.wikimedia.org/wikipedia/en/c/c1/Tennessee_Titans_logo.svg",
          Loser == "Carolina Panthers" ~ "https://upload.wikimedia.org/wikipedia/en/1/1c/Carolina_Panthers_logo.svg",
          Loser == "Arizona Cardinals" ~ "https://upload.wikimedia.org/wikipedia/en/7/72/Arizona_Cardinals_logo.svg"
          )
       )

# Choosing a subset of columns to display basic information about the Super Bowl
superbowls<-superbowls %>% 
  dplyr::select("SB", "Date", "win_logo_url", "Winner", "Winning Pts", "lose_logo_url", "Loser", "Losing Pts", "City", "State")

# convert to date format
superbowls$Date <- as.Date(superbowls$Date, '%d-%b-%Y') %m+% years(2000) 
# convert to 4 digit year format
superbowls$Date <- dplyr::if_else(superbowls$Date > '2023-01-01', superbowls$Date %m-% years(100), superbowls$Date)


# create gt table  
superbowls %>% 
  gt() %>% 
  # add title and subtitle
  tab_header(
    title = md("**Super Bowl Winners**"),
    subtitle = "Super Bowl I-LII"
  ) %>%
  # format date
  fmt_date(
    columns = Date,
    date_style = 5
  ) %>%
  # add winning team label
  tab_spanner(
    label = md("**Winning Team**"),
    columns = c(win_logo_url, Winner, `Winning Pts`)
  ) %>% 
  # add losing team label
  tab_spanner(
    label = "Losing Team",
    columns = c(lose_logo_url, Loser, `Losing Pts`)
  ) %>% 
  # add location label
  tab_spanner(
    label = "Location",
    columns = c(City, State)
  ) %>% 
  # add super bowl label
  tab_spanner(
    label = "Super Bowl",
    columns = c(SB, Date)
  ) %>% 
  # align the text to center
  cols_align(
    align = "center") %>% 
  # change names of columns
  cols_label(
    SB = "Number",
    Winner = md("**Name**"),
    `Winning Pts` = md("**Points**"),
    Loser = "Name",
    `Losing Pts` = "Points"
  ) %>%
  # convert urls to images
  text_transform(
    #Apply a function to a column
    locations = cells_body(c(win_logo_url, lose_logo_url)),
    fn = function(x) {
      #Return an image of set dimensions
      web_image(
        url = x,
        height = 12
      )
    }
  ) %>%
  #Hide column headers and reduce width
  cols_width(c(win_logo_url, lose_logo_url) ~ px(30)) %>% 
  cols_label(win_logo_url = "") %>% 
  cols_label(lose_logo_url = "") %>%
  # change colors of winning and losing teams
  tab_style(
    style = list(
      cell_fill("darkseagreen1"),
      cell_text(weight = "bold")
    ),
    locations = cells_body(
      columns = c(win_logo_url, Winner, `Winning Pts`)
    )
  ) %>% 
  tab_style(
    style = list(
      cell_fill("#FFADAD")
    ),
    locations = cells_body(
      columns = c(lose_logo_url, Loser, `Losing Pts`)
    )
  ) %>% 
  # add reference footnote
  tab_source_note(
    source_note = html("Source: <b>Super Bowl Results, Officials, and MVPs</b>, dataset uploaded by user thedevastator to <a href ='https://www.kaggle.com/datasets/thedevastator/super-bowl-results-officials-and-mvps-1967-2020'>Kaggle.com</a>.")
  )
Super Bowl Winners
Super Bowl I-LII
Super Bowl Winning Team Losing Team Location
Number Date Name Points Name Points City State
I January 15, 1967 Green Bay Packers 35 Kansas City Chiefs 10 Los Angeles California
II January 14, 1968 Green Bay Packers 33 Oakland Raiders 14 Miami Florida
III January 12, 1969 New York Jets 16 Baltimore Colts 7 Miami Florida
IV January 11, 1970 Kansas City Chiefs 23 Minnesota Vikings 7 New Orleans Louisiana
V January 17, 1971 Baltimore Colts 16 Dallas Cowboys 13 Miami Florida
VI January 16, 1972 Dallas Cowboys 24 Miami Dolphins 3 New Orleans Louisiana
VII January 14, 1973 Miami Dolphins 14 Washington Redskins 7 Los Angeles California
VIII January 13, 1974 Miami Dolphins 24 Minnesota Vikings 7 Houston Texas
IX January 12, 1975 Pittsburgh Steelers 16 Minnesota Vikings 6 New Orleans Louisiana
X January 18, 1976 Pittsburgh Steelers 21 Dallas Cowboys 17 Miami Florida
XI January 9, 1977 Oakland Raiders 32 Minnesota Vikings 14 Pasadena California
XII January 15, 1978 Dallas Cowboys 27 Denver Broncos 10 New Orleans Louisiana
XIII January 21, 1979 Pittsburgh Steelers 35 Dallas Cowboys 31 Miami Florida
XIV January 20, 1980 Pittsburgh Steelers 31 Los Angeles Rams 19 Pasadena California
XV January 25, 1981 Oakland Raiders 27 Philadelphia Eagles 10 New Orleans Louisiana
XVI January 24, 1982 San Francisco 49ers 26 Cincinnati Bengals 21 Pontiac Michigan
XVII January 30, 1983 Washington Redskins 27 Miami Dolphins 17 Pasadena California
XVIII January 22, 1984 Los Angeles Raiders 38 Washington Redskins 9 Tampa Florida
XIX January 20, 1985 San Francisco 49ers 38 Miami Dolphins 16 Palo Alto California
XX January 26, 1986 Chicago Bears 46 New England Patriots 10 New Orleans Louisiana
XXI January 25, 1987 New York Giants 39 Denver Broncos 20 Pasadena California
XXII January 31, 1988 Washington Redskins 42 Denver Broncos 10 San Diego California
XXIII January 22, 1989 San Francisco 49ers 20 Cincinnati Bengals 16 Miami Gardens Florida
XXIV January 28, 1990 San Francisco 49ers 55 Denver Broncos 10 New Orleans Louisiana
XXV January 27, 1991 New York Giants 20 Buffalo Bills 19 Tampa Florida
XXVI January 26, 1992 Washington Redskins 37 Buffalo Bills 24 Minneapolis Minnesota
XXVII January 31, 1993 Dallas Cowboys 52 Buffalo Bills 17 Pasadena California
XXVIII January 30, 1994 Dallas Cowboys 30 Buffalo Bills 13 Atlanta Georgia
XXIX January 29, 1995 San Francisco 49ers 49 San Diego Chargers 26 Miami Gardens Florida
XXX January 28, 1996 Dallas Cowboys 27 Pittsburgh Steelers 17 Tempe Arizona
XXXI January 26, 1997 Green Bay Packers 35 New England Patriots 21 New Orleans Louisiana
XXXII January 25, 1998 Denver Broncos 31 Green Bay Packers 24 San Diego California
XXXIII January 31, 1999 Denver Broncos 34 Atlanta Falcons 19 Miami Gardens Florida
XXXIV January 30, 2000 St. Louis Rams 23 Tennessee Titans 16 Atlanta Georgia
XXXV January 28, 2001 Baltimore Ravens 34 New York Giants 7 Tampa Florida
XXXVI February 3, 2002 New England Patriots 20 St. Louis Rams 17 New Orleans Louisiana
XXXVII January 26, 2003 Tampa Bay Buccaneers 48 Oakland Raiders 21 San Diego California
XXXVIII February 1, 2004 New England Patriots 32 Carolina Panthers 29 Houston Texas
XXXIX February 6, 2005 New England Patriots 24 Philadelphia Eagles 21 Jacksonville Florida
XL February 5, 2006 Pittsburgh Steelers 21 Seattle Seahawks 10 Detroit Michigan
XLI February 4, 2007 Indianapolis Colts 29 Chicago Bears 17 Miami Gardens Florida
XLII February 3, 2008 New York Giants 17 New England Patriots 14 Glendale Arizona
XLIII February 1, 2009 Pittsburgh Steelers 27 Arizona Cardinals 23 Tampa Florida
XLIV February 7, 2010 New Orleans Saints 31 Indianapolis Colts 17 Miami Gardens Florida
XLV February 6, 2011 Green Bay Packers 31 Pittsburgh Steelers 25 Arlington Texas
XLVI February 5, 2012 New York Giants 21 New England Patriots 17 Indianapolis Indiana
XLVII February 3, 2013 Baltimore Ravens 34 San Francisco 49ers 31 New Orleans Louisiana
XLVIII February 2, 2014 Seattle Seahawks 43 Denver Broncos 8 East Rutherford New Jersey
XLIX February 1, 2015 New England Patriots 28 Seattle Seahawks 24 Glendale Arizona
L February 7, 2016 Denver Broncos 24 Carolina Panthers 10 Santa Clara California
LI February 5, 2017 New England Patriots 34 Atlanta Falcons 28 Houston Texas
LII February 4, 2018 Philadelphia Eagles 41 New England Patriots 33 Minneapolis Minnesota
Source: Super Bowl Results, Officials, and MVPs, dataset uploaded by user thedevastator to Kaggle.com.

Among the findings, it is disheartening to note that my favorite team, the Cincinnati Bengals, has yet to secure a Super Bowl victory. 😢 Nevertheless, this revelation adds intrigue and further appreciation for the accomplishments of other teams.

Feel free to explore the table and discover if your team has clinched the coveted Super Bowl title. Join me in commemorating the remarkable achievements, reliving the defining moments, and reflecting on the enduring legacy of the Super Bowl.

Has your team ever won?