knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The goal of nhl is to make it easy to retrieve data from the NHL API with R.
nhl_get_teams()
will return a data frame with all current nhl teams.
library(nhl) teams <- nhl_get_teams() head(teams)
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)
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')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.