Skip to contents

Acquire pitch-by-pitch data for Major and Minor League games

Usage

mlb_pbp(game_pk)

Arguments

game_pk

The date for which you want to find game_pk values for MLB games

Value

Returns a tibble that includes over 100 columns of data provided by the MLB Stats API at a pitch level. Some data will vary depending on the park and the league level, as most sensor data is not available in minor league parks via this API. Note that the column names have mostly been left as-is and there are likely duplicate columns in terms of the information they provide. I plan to clean the output up down the road, but for now I am leaving the majority as-is. Both major and minor league pitch-by-pitch data can be pulled with this function.

col_nametypes
game_pknumeric
game_datecharacter
indexinteger
startTimecharacter
endTimecharacter
isPitchlogical
typecharacter
playIdcharacter
pitchNumberinteger
details.descriptioncharacter
details.eventcharacter
details.awayScoreinteger
details.homeScoreinteger
details.isScoringPlaylogical
details.hasReviewlogical
details.codecharacter
details.ballColorcharacter
details.isInPlaylogical
details.isStrikelogical
details.isBalllogical
details.call.codecharacter
details.call.descriptioncharacter
count.balls.startinteger
count.strikes.startinteger
count.outs.startinteger
player.idinteger
player.linkcharacter
pitchData.strikeZoneTopnumeric
pitchData.strikeZoneBottomnumeric
details.fromCatcherlogical
pitchData.coordinates.xnumeric
pitchData.coordinates.ynumeric
hitData.trajectorycharacter
hitData.hardnesscharacter
hitData.locationcharacter
hitData.coordinates.coordXnumeric
hitData.coordinates.coordYnumeric
actionPlayIdcharacter
details.eventTypecharacter
details.runnerGoinglogical
position.codecharacter
position.namecharacter
position.typecharacter
position.abbreviationcharacter
battingOrdercharacter
atBatIndexcharacter
result.typecharacter
result.eventcharacter
result.eventTypecharacter
result.descriptioncharacter
result.rbiinteger
result.awayScoreinteger
result.homeScoreinteger
about.atBatIndexinteger
about.halfInningcharacter
about.inninginteger
about.startTimecharacter
about.endTimecharacter
about.isCompletelogical
about.isScoringPlaylogical
about.hasReviewlogical
about.hasOutlogical
about.captivatingIndexinteger
count.balls.endinteger
count.strikes.endinteger
count.outs.endinteger
matchup.batter.idinteger
matchup.batter.fullNamecharacter
matchup.batter.linkcharacter
matchup.batSide.codecharacter
matchup.batSide.descriptioncharacter
matchup.pitcher.idinteger
matchup.pitcher.fullNamecharacter
matchup.pitcher.linkcharacter
matchup.pitchHand.codecharacter
matchup.pitchHand.descriptioncharacter
matchup.splits.battercharacter
matchup.splits.pitchercharacter
matchup.splits.menOnBasecharacter
batted.ball.resultfactor
home_teamcharacter
home_level_idinteger
home_level_namecharacter
home_parentOrg_idinteger
home_parentOrg_namecharacter
home_league_idinteger
home_league_namecharacter
away_teamcharacter
away_level_idinteger
away_level_namecharacter
away_parentOrg_idinteger
away_parentOrg_namecharacter
away_league_idinteger
away_league_namecharacter
batting_teamcharacter
fielding_teamcharacter
last.pitch.of.abcharacter
pfxIdcharacter
details.trailColorcharacter
details.type.codecharacter
details.type.descriptioncharacter
pitchData.startSpeednumeric
pitchData.endSpeednumeric
pitchData.zoneinteger
pitchData.typeConfidencenumeric
pitchData.plateTimenumeric
pitchData.extensionnumeric
pitchData.coordinates.aYnumeric
pitchData.coordinates.aZnumeric
pitchData.coordinates.pfxXnumeric
pitchData.coordinates.pfxZnumeric
pitchData.coordinates.pXnumeric
pitchData.coordinates.pZnumeric
pitchData.coordinates.vX0numeric
pitchData.coordinates.vY0numeric
pitchData.coordinates.vZ0numeric
pitchData.coordinates.x0numeric
pitchData.coordinates.y0numeric
pitchData.coordinates.z0numeric
pitchData.coordinates.aXnumeric
pitchData.breaks.breakAnglenumeric
pitchData.breaks.breakLengthnumeric
pitchData.breaks.breakYnumeric
pitchData.breaks.spinRateinteger
pitchData.breaks.spinDirectioninteger
hitData.launchSpeednumeric
hitData.launchAnglenumeric
hitData.totalDistancenumeric
injuryTypecharacter
umpire.idinteger
umpire.linkcharacter
isBaseRunningPlaylogical
isSubstitutionlogical
about.isTopInninglogical
matchup.postOnFirst.idinteger
matchup.postOnFirst.fullNamecharacter
matchup.postOnFirst.linkcharacter
matchup.postOnSecond.idinteger
matchup.postOnSecond.fullNamecharacter
matchup.postOnSecond.linkcharacter
matchup.postOnThird.idinteger
matchup.postOnThird.fullNamecharacter
matchup.postOnThird.linkcharacter

Examples

# \donttest{
  try(mlb_pbp(game_pk = 632970))
#> ── MLB Play-by-Play data from MLB.com ─────────────── baseballr 1.2.0 ──
#>  Data updated: 2022-04-30 07:16:19 UTC
#> # A tibble: 336 × 145
#>    game_pk game_date  index startTime       endTime isPitch type  playId
#>      <dbl> <chr>      <int> <chr>           <chr>   <lgl>   <chr> <chr> 
#>  1  632970 2021-08-08     3 2021-08-09T02:… 2021-0… TRUE    pitch 932a8…
#>  2  632970 2021-08-08     2 2021-08-09T02:… 2021-0… TRUE    pitch e9403…
#>  3  632970 2021-08-08     1 2021-08-09T02:… 2021-0… TRUE    pitch 01e5d…
#>  4  632970 2021-08-08     0 2021-08-09T02:… NA      FALSE   acti… NA    
#>  5  632970 2021-08-08     5 2021-08-09T02:… 2021-0… TRUE    pitch f0450…
#>  6  632970 2021-08-08     4 2021-08-09T02:… 2021-0… TRUE    pitch b4c15…
#>  7  632970 2021-08-08     3 2021-08-09T02:… 2021-0… TRUE    pitch e274e…
#>  8  632970 2021-08-08     2 2021-08-09T02:… 2021-0… TRUE    pitch d5dc0…
#>  9  632970 2021-08-08     1 2021-08-09T02:… 2021-0… TRUE    pitch ddbcc…
#> 10  632970 2021-08-08     0 2021-08-09T02:… 2021-0… TRUE    pitch 69a40…
#> # … with 326 more rows, and 137 more variables: pitchNumber <int>,
#> #   details.description <chr>, details.event <chr>,
#> #   details.awayScore <int>, details.homeScore <int>,
#> #   details.isScoringPlay <lgl>, details.hasReview <lgl>,
#> #   details.code <chr>, details.ballColor <chr>,
#> #   details.isInPlay <lgl>, details.isStrike <lgl>,
#> #   details.isBall <lgl>, details.call.code <chr>, …
# }