README.md

nhl

The goal of nhl is to make it easy to retrieve data from the NHL API with R.

Examples

nhl_get_teams() will return a data frame with all current nhl teams.

library(nhl)

teams <- nhl_get_teams()

head(teams)
#>   id      name            fullName abbr     location     division
#> 1  1    Devils   New Jersey Devils  NJD   New Jersey Metropolitan
#> 2  2 Islanders  New York Islanders  NYI     New York Metropolitan
#> 3  3   Rangers    New York Rangers  NYR     New York Metropolitan
#> 4  4    Flyers Philadelphia Flyers  PHI Philadelphia Metropolitan
#> 5  5  Penguins Pittsburgh Penguins  PIT   Pittsburgh Metropolitan
#> 6  6    Bruins       Boston Bruins  BOS       Boston     Atlantic
#>   conference
#> 1    Eastern
#> 2    Eastern
#> 3    Eastern
#> 4    Eastern
#> 5    Eastern
#> 6    Eastern

nhl_get_team_stats() will return a list of information on team stats for specified seasons.


# Get aggregate stats for Buffal Sabres 1990
seasons <- paste0(seq(1990, 2018, 1), seq(1991, 2019, 1))
buf_all <- nhl_get_team_stats(team = 'buf', season = seasons)

buf_all$stats

nhl_get_team_games() will return a data frame of a team's schedule a specified date range.


# Get buffalo schedule for the 2017-2018 season
buffalo_schedule <- nhl_get_team_games(team = 'buf', 
                                       start_date = '2017-09-01', end_date = '2018-08-01')

nhl_get_players() will return a list with information and statistics for all players and goalies on a team in a specified season.


# Get all buffalo players in the 2006-2007 season
buffalo_players <- nhl_get_players(team = 'BUF', season = 20062007)

buffalo_players$players
buffalo_players$goalies

nhl_get_game() will return a list with play-level and meta data for a specific game.


# Get all data about a game
one_game <- nhl_get_game(game_id = 2011021084)

Visualizations

ggrinkplot() will create a ggplot of a hockey rink with x and y coordinates that can be used to visualize plays. For example, if we wanted to see the coordinates of all goals scored in one_game as green dots, we can run:

ggrinkplot() +
  geom_point(
    data = one_game$plays %>%
      select(x, y, event) %>% 
      filter(event %in% c('Goal')),
    aes(x = x, y = y),
        size = 3, col = 'green')



alexpavlakis/nhl documentation built on May 18, 2019, 2:35 p.m.