ncaahoopR
is an R package for working with NCAA Basketball Play-by-Play Data. It not only scrapes play by play data
and returns it to the user in a tidy, but also allows the user to explore the data with assist networks and in game win-probability charts.
Note: ncaahoopR
scrapes data from ESPN. Since ESPN is currently updating many college basketball pages, such as schedules and rosters,
some functionality may be temporarily unavailable. Once we approach the beginning of the season, all functionality should work as desired.
You can install ncaahoopR
from GitHub with:
# install.packages("devtools")
devtools::install_github("lbenz730/ncaahoopR")
Several functions use ESPN gameIDs. You can find the gameID in the URL for the game summary, as shown in the url for the summary of the UMBC-Virginia game below.
get_pbp(team)
: Game entire 2017-18 Season's worth of play-by-play data for a given team.get_pbp_game(gameIDS)
: Get play-by-play data for a specific vector of ESPN game ids.get_roster(team)
: Get a particular team's roster.get_schedule(team)
: Get a team's schedule.get_game_ids(team)
: Get a vector of ESPN Game IDs for all games in whichteam
plays in.
Used to create college basketball assist networks.
Usage: assist_net(team, node_col, season, rmv_bench, tree, three_weights, message = NA)
team
is the ESPN team name, as listed in theids
dataframe.node_col
is the node color for the graphseason
: Options include "2018-19" (for entire season), or a vector of ESPN game IDs.rmv_bench
: Logical. If TRUE, removes all players who aren't in the network.tree
: Logical. If TRUE, draws graph in tree structure. If FALSE, draws graph in circle. Tree structure is recommended for single game networks, while circles are recommended for entire season networks.three_weights
: Logical. If TRUE, assisted three point shots are given 1.5 weight. If FALSE, assisted three point shots are given weight 1. In both cases, assisted 2 point shots are given weight 1.Message
(default =NA
) Option for custom message to replace graph title when using a subset of the season (e.g. conference play).
Plots win probability chart for given game.
Usage:wp_chart(gameID, home_color, away_color, show_legend = T)
gameID
ESPN gameID for the desired win probability chart.home_col
Chart color for home team.season
: Chart color for away team.show_legend
: Logical, whether or not to show legend/text on chart. Default =TRUE
.
For more information about how these win-probability charts are fit, check out the below links
dict
A dataframe for converting between team names from various sites.
NCAA
: the name of the team, as listed on the NCAA websiteESPN
: the name of the team, as listed on the ESPN URLsESPN_PBP
: the name of the team, as listed on the ESPN Play-By-Play logsWarren_Nolan
: the name of the team, as listed on WarrenNolan.comTrank
: the name of the team, as listed on barttorvik.comname_247
: the name of the team, as listed on 247Sports.com
ids
A dataframe for converting between team names from various sites.
team
: the name of the team to be suplied to function in ncaahoopR packageid
: team id; used in ESPN URLslink
: link; used in ESPN URLs
Single Game Assist Network
assist_net("Oklahoma", "firebrick4", 400989185, rmv_bench = T, tree = F, three_weights = T)
Season Long Assist Network
assist_net("Yale", "royalblue4", "2017-18", rmv_bench = T, tree = F, three_weights = T)
NOTE: The use season = "2017-18"
would be replaced with the current season. Backdated charts are currently not avaiable.
Win Probability Chart---2018 NCAA Championship Game
wp_chart(401025888, "navy", "goldenrod1")