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_nametypesdescription
game_pknumericMLB game primary key.
game_datecharacterGame date (YYYY-MM-DD).
indexintegerIndex of the play event within the at-bat.
startTimecharacterEvent start timestamp (ISO 8601).
endTimecharacterEvent end timestamp (ISO 8601).
isPitchlogicalWhether the event is a pitch.
typecharacterPlay event type (e.g. 'pitch', 'action').
playIdcharacterUnique play event identifier (UUID).
pitchNumberintegerPitch number within the at-bat.
details.descriptioncharacterPitch/event description (e.g. 'Swinging Strike').
details.eventcharacterEvent name for non-pitch actions.
details.awayScoreintegerAway score recorded at the event.
details.homeScoreintegerHome score recorded at the event.
details.isScoringPlaylogicalWhether the event is a scoring play.
details.hasReviewlogicalWhether the event was reviewed.
details.codecharacterPitch/result code (e.g. 'S', 'C', 'B').
details.ballColorcharacterGameday ball color rgba string.
details.isInPlaylogicalWhether the ball was put in play.
details.isStrikelogicalWhether the pitch was a strike.
details.isBalllogicalWhether the pitch was a ball.
details.call.codecharacterUmpire call code.
details.call.descriptioncharacterUmpire call description.
count.balls.startintegerBall count before the pitch.
count.strikes.startintegerStrike count before the pitch.
count.outs.startintegerOut count before the pitch.
player.idintegerPlayer id for action-event participant.
player.linkcharacterAPI relative link to the action player.
pitchData.strikeZoneTopnumericTop of the batter strike zone (feet).
pitchData.strikeZoneBottomnumericBottom of the batter strike zone (feet).
details.fromCatcherlogicalWhether the event originated from the catcher.
pitchData.coordinates.xnumericPitch x pixel coordinate (Gameday).
pitchData.coordinates.ynumericPitch y pixel coordinate (Gameday).
hitData.trajectorycharacterBatted ball trajectory.
hitData.hardnesscharacterBatted ball hardness.
hitData.locationcharacterFielding position where the ball was hit.
hitData.coordinates.coordXnumericBatted ball landing x coordinate.
hitData.coordinates.coordYnumericBatted ball landing y coordinate.
actionPlayIdcharacterIdentifier of an associated action play.
details.eventTypecharacterEvent type slug for non-pitch actions.
details.runnerGoinglogicalWhether a runner was going on the pitch.
position.codecharacterFielding position code for the player.
position.namecharacterFielding position name.
position.typecharacterFielding position type.
position.abbreviationcharacterFielding position abbreviation.
battingOrdercharacterBatting order slot.
atBatIndexcharacterAt-bat index within the game (factor).
result.typecharacterResult type (e.g. 'atBat').
result.eventcharacterAt-bat result event (e.g. 'Strikeout').
result.eventTypecharacterAt-bat result event slug.
result.descriptioncharacterNarrative description of the at-bat result.
result.rbiintegerRuns batted in on the at-bat.
result.awayScoreintegerAway score after the at-bat.
result.homeScoreintegerHome score after the at-bat.
about.atBatIndexintegerAt-bat index (numeric).
about.halfInningcharacterHalf inning ('top' or 'bottom').
about.inningintegerInning number.
about.startTimecharacterAt-bat start timestamp (ISO 8601).
about.endTimecharacterAt-bat end timestamp (ISO 8601).
about.isCompletelogicalWhether the at-bat is complete.
about.isScoringPlaylogicalWhether the at-bat is a scoring play.
about.hasReviewlogicalWhether the at-bat had a review.
about.hasOutlogicalWhether the at-bat produced an out.
about.captivatingIndexintegerMLB captivating index for the play.
count.balls.endintegerBall count after the pitch.
count.strikes.endintegerStrike count after the pitch.
count.outs.endintegerOut count after the pitch.
matchup.batter.idintegerBatter player id.
matchup.batter.fullNamecharacterBatter full name (factor).
matchup.batter.linkcharacterAPI relative link to the batter.
matchup.batSide.codecharacterBatter handedness code (e.g. 'L', 'R').
matchup.batSide.descriptioncharacterBatter handedness description.
matchup.pitcher.idintegerPitcher player id.
matchup.pitcher.fullNamecharacterPitcher full name (factor).
matchup.pitcher.linkcharacterAPI relative link to the pitcher.
matchup.pitchHand.codecharacterPitcher throwing hand code (e.g. 'R').
matchup.pitchHand.descriptioncharacterPitcher throwing hand description.
matchup.splits.battercharacterBatter platoon split (e.g. 'vs_RHP').
matchup.splits.pitchercharacterPitcher platoon split (e.g. 'vs_LHB').
matchup.splits.menOnBasecharacterMen on base split (e.g. 'Empty', 'Men_On').
batted.ball.resultfactorCategorized batted ball result.
home_teamcharacterHome team name.
home_level_idintegerHome team level/sport id (1 for MLB).
home_level_namecharacterHome team level/sport name.
home_parentOrg_idintegerHome team parent organization id (minors).
home_parentOrg_namecharacterHome team parent organization name (minors).
home_league_idintegerHome team league id.
home_league_namecharacterHome team league name.
away_teamcharacterAway team name.
away_level_idintegerAway team level/sport id (1 for MLB).
away_level_namecharacterAway team level/sport name.
away_parentOrg_idintegerAway team parent organization id (minors).
away_parentOrg_namecharacterAway team parent organization name (minors).
away_league_idintegerAway team league id.
away_league_namecharacterAway team league name.
batting_teamcharacterTeam batting on the play (factor).
fielding_teamcharacterTeam fielding on the play (factor).
last.pitch.of.abcharacterWhether the pitch was the last of the at-bat (factor).
pfxIdcharacterPitch f/x tracking identifier.
details.trailColorcharacterGameday pitch trail color rgba string.
details.type.codecharacterPitch type code (e.g. 'CU', 'SI').
details.type.descriptioncharacterPitch type description (e.g. 'Curveball').
pitchData.startSpeednumericPitch release speed (mph).
pitchData.endSpeednumericPitch speed crossing the plate (mph).
pitchData.zoneintegerStrike zone region of the pitch.
pitchData.typeConfidencenumericPitch type classification confidence.
pitchData.plateTimenumericTime from release to plate (seconds).
pitchData.extensionnumericPitcher release extension (feet).
pitchData.coordinates.aYnumericPitch acceleration in y (ft/s^2).
pitchData.coordinates.aZnumericPitch acceleration in z (ft/s^2).
pitchData.coordinates.pfxXnumericHorizontal pitch movement (inches).
pitchData.coordinates.pfxZnumericVertical pitch movement (inches).
pitchData.coordinates.pXnumericHorizontal pitch location at plate (feet).
pitchData.coordinates.pZnumericVertical pitch location at plate (feet).
pitchData.coordinates.vX0numericPitch initial velocity in x (ft/s).
pitchData.coordinates.vY0numericPitch initial velocity in y (ft/s).
pitchData.coordinates.vZ0numericPitch initial velocity in z (ft/s).
pitchData.coordinates.x0numericPitch initial x position (feet).
pitchData.coordinates.y0numericPitch initial y position (feet).
pitchData.coordinates.z0numericPitch initial z position (feet).
pitchData.coordinates.aXnumericPitch acceleration in x (ft/s^2).
pitchData.breaks.breakAnglenumericPitch break angle (degrees).
pitchData.breaks.breakLengthnumericPitch break length (inches).
pitchData.breaks.breakYnumericDistance from plate where break is measured.
pitchData.breaks.spinRateintegerPitch spin rate (RPM).
pitchData.breaks.spinDirectionintegerPitch spin direction (degrees).
hitData.launchSpeednumericBatted ball exit velocity (mph).
hitData.launchAnglenumericBatted ball launch angle (degrees).
hitData.totalDistancenumericBatted ball total distance (feet).
injuryTypecharacterInjury type when the event is injury-related.
umpire.idintegerUmpire person id for the event.
umpire.linkcharacterAPI relative link to the umpire.
details.isOutlogicalWhether the pitch/event resulted in an out.
pitchData.breaks.breakVerticalnumericTotal vertical break (inches).
pitchData.breaks.breakVerticalInducednumericInduced vertical break (inches).
pitchData.breaks.breakHorizontalnumericHorizontal break (inches).
details.disengagementNumintegerPitcher disengagement number on the play.
isBaseRunningPlaylogicalWhether the event is a base running play.
isSubstitutionlogicalWhether the event is a substitution.
replacedPlayer.idintegerPlayer id replaced on a substitution.
replacedPlayer.linkcharacterAPI relative link to the replaced player.
result.isOutlogicalWhether the at-bat resulted in an out.
about.isTopInninglogicalWhether the play occurred in the top of the inning.
matchup.postOnFirst.idintegerRunner id on first base after the play.
matchup.postOnFirst.fullNamecharacterRunner name on first base after the play.
matchup.postOnFirst.linkcharacterAPI relative link to the first base runner.
matchup.postOnSecond.idintegerRunner id on second base after the play.
matchup.postOnSecond.fullNamecharacterRunner name on second base after the play.
matchup.postOnSecond.linkcharacterAPI relative link to the second base runner.
matchup.postOnThird.idintegerRunner id on third base after the play.
matchup.postOnThird.fullNamecharacterRunner name on third base after the play.
matchup.postOnThird.linkcharacterAPI relative link to the third base runner.

Examples

# \donttest{
  try(mlb_pbp(game_pk = 632970))
#> ── MLB Play-by-Play data from MLB.com ─────────────── baseballr 2.0.0 ──
#>  Data updated: 2026-06-08 11:09:15 UTC
#> # A tibble: 336 × 151
#>    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:… 2021-0… 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…
#> # ℹ 326 more rows
#> # ℹ 143 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>, …
# }