Skip to contents

This function allows you to scrape game logs by year for a batter from FanGraphs.com.

Usage

fg_batter_game_logs(playerid, year)

Arguments

playerid

This is the playerid used by FanGraphs for a given player

year

The season for which game logs should be returned (use the YYYY format)

Value

A data frame of batter game logs, one row per game, with the following columns:

col_nametypesdescription
PlayerNamecharacterPlayer name.
playeridintegerFanGraphs player ID.
DatecharacterCalendar date of the game (YYYY-MM-DD).
TeamcharacterTeam the player appeared for.
OppcharacterOpponent team; leading @ indicates a road game.
seasonintegerSeason year.
AgeintegerPlayer age during the season.
BatOrdercharacterSpot in the batting order.
PoscharacterFielding position played.
GnumericGames (1 per row).
ABnumericAt-bats.
PAnumericPlate appearances.
HnumericHits.
1BnumericSingles.
2BnumericDoubles.
3BnumericTriples.
HRnumericHome runs.
RnumericRuns scored.
RBInumericRuns batted in.
BBnumericWalks (bases on balls).
IBBnumericIntentional walks.
SOnumericStrikeouts.
HBPnumericTimes hit by pitch.
SFnumericSacrifice flies.
SHnumericSacrifice hits (bunts).
GDPnumericGrounded into double plays.
SBnumericStolen bases.
CSnumericTimes caught stealing.
AVGnumericBatting average.
GBnumericGround balls.
FBnumericFly balls.
LDnumericLine drives.
IFFBnumericInfield fly balls.
PitchesnumericPitches seen.
BallsnumericBalls.
StrikesnumericStrikes.
IFHnumericInfield hits.
BUnumericBunts.
BUHnumericBunt hits.
BB%numericWalk rate.
K%numericStrikeout rate.
BB/KnumericWalk-to-strikeout ratio.
OBPnumericOn-base percentage.
SLGnumericSlugging percentage.
OPSnumericOn-base plus slugging.
ISOnumericIsolated power.
BABIPnumericBatting average on balls in play.
GB/FBnumericGround-ball to fly-ball ratio.
LD%numericLine-drive rate.
GB%numericGround-ball rate.
FB%numericFly-ball rate.
IFFB%numericInfield-fly-ball rate.
HR/FBnumericHome-run-per-fly-ball rate.
IFH%numericInfield-hit rate.
BUH%numericBunt-hit rate.
wOBAnumericWeighted on-base average.
wRAAnumericWeighted runs above average.
wRCnumericWeighted runs created.
SpdnumericBill James Speed Score.
wRC+numericWeighted runs created plus (100 = average).
wBSRnumericWeighted base running runs.
WPAnumericWin probability added.
-WPAnumericNegative win probability added.
+WPAnumericPositive win probability added.
RE24numericRun expectancy based on 24 base-out states.
REWnumericRun expectancy wins.
pLInumericAverage leverage index.
PHnumericPinch-hit appearances.
WPA/LInumericContext-neutral win probability added.
ClutchnumericClutch performance score.
FB%1numericFastball usage rate.
FBvnumericAverage four-seam fastball velocity (mph).
SL%numericslider usage rate.
SLvnumericAverage slider velocity (mph).
CT%numericcutter usage rate.
CTvnumericAverage cutter velocity (mph).
CB%numericcurveball usage rate.
CBvnumericAverage curveball velocity (mph).
CH%numericchangeup usage rate.
CHvnumericAverage changeup velocity (mph).
SF%numericsplit-finger fastball usage rate.
SFvnumericAverage split-finger fastball velocity (mph).
XX%numericunknown/other pitch usage rate.
wFBnumericTotal runs above average on the fastball.
wSLnumericTotal runs above average on the slider.
wCTnumericTotal runs above average on the cutter.
wCBnumericTotal runs above average on the curveball.
wCHnumericTotal runs above average on the changeup.
wSFnumericTotal runs above average on the split-finger fastball.
wFB/CnumericRuns above average per 100 fastballs.
wSL/CnumericRuns above average per 100 sliders.
wCT/CnumericRuns above average per 100 cutters.
wCB/CnumericRuns above average per 100 curveballs.
wCH/CnumericRuns above average per 100 changeups.
wSF/CnumericRuns above average per 100 split-finger fastballs.
O-Swing%numericSwing rate on pitches outside the zone.
Z-Swing%numericSwing rate on pitches in the zone.
Swing%numericOverall swing rate.
O-Contact%numericContact rate on pitches outside the zone.
Z-Contact%numericContact rate on pitches in the zone.
Contact%numericOverall contact rate.
Zone%numericRate of pitches in the strike zone.
F-Strike%numericFirst-pitch strike rate.
SwStr%numericSwinging-strike rate.
PullnumericPulled batted balls.
CentnumericBatted balls hit up the middle.
OpponumericOpposite-field batted balls.
SoftnumericSoft-hit batted balls.
MednumericMedium-hit batted balls.
HardnumericHard-hit batted balls.
bipCountnumericBalls in play.
Pull%numericPulled batted-ball rate.
Cent%numericUp-the-middle batted-ball rate.
Oppo%numericOpposite-field batted-ball rate.
Soft%numericSoft-contact rate.
Med%numericMedium-contact rate.
Hard%numericHard-contact rate.
xwOBAnumericExpected weighted on-base average.
xAVGnumericExpected batting average.
xSLGnumericExpected slugging percentage.
pfxFA%numericPITCHf/x four-seam fastball usage rate.
pfxFC%numericPITCHf/x cutter usage rate.
pfxFS%numericPITCHf/x splitter usage rate.
pfxFO%numericPITCHf/x forkball usage rate.
pfxSI%numericPITCHf/x sinker usage rate.
pfxSL%numericPITCHf/x slider usage rate.
pfxCU%numericPITCHf/x curveball usage rate.
pfxKC%numericPITCHf/x knuckle curve usage rate.
pfxCH%numericPITCHf/x changeup usage rate.
pfxSLO%numericPITCHf/x slurve usage rate.
pfxST%numericPITCHf/x sweeper usage rate.
pfxCUO%numericPITCHf/x other curve usage rate.
pfxCV%numericPITCHf/x curve usage rate.
pfxvFAnumericPITCHf/x average four-seam fastball velocity (mph).
pfxvFCnumericPITCHf/x average cutter velocity (mph).
pfxvFSnumericPITCHf/x average splitter velocity (mph).
pfxvFOnumericPITCHf/x average forkball velocity (mph).
pfxvSInumericPITCHf/x average sinker velocity (mph).
pfxvSLnumericPITCHf/x average slider velocity (mph).
pfxvCUnumericPITCHf/x average curveball velocity (mph).
pfxvKCnumericPITCHf/x average knuckle curve velocity (mph).
pfxvCHnumericPITCHf/x average changeup velocity (mph).
pfxvSLOnumericPITCHf/x average slurve velocity (mph).
pfxvSTnumericPITCHf/x average sweeper velocity (mph).
pfxvCUOnumericPITCHf/x average other curve velocity (mph).
pfxvCVnumericPITCHf/x average curve velocity (mph).
pfxFA-XnumericPITCHf/x horizontal movement of the four-seam fastball (inches).
pfxFC-XnumericPITCHf/x horizontal movement of the cutter (inches).
pfxFS-XnumericPITCHf/x horizontal movement of the splitter (inches).
pfxFO-XnumericPITCHf/x horizontal movement of the forkball (inches).
pfxSI-XnumericPITCHf/x horizontal movement of the sinker (inches).
pfxSL-XnumericPITCHf/x horizontal movement of the slider (inches).
pfxCU-XnumericPITCHf/x horizontal movement of the curveball (inches).
pfxKC-XnumericPITCHf/x horizontal movement of the knuckle curve (inches).
pfxCH-XnumericPITCHf/x horizontal movement of the changeup (inches).
pfxSLO-XnumericPITCHf/x horizontal movement of the slurve (inches).
pfxST-XnumericPITCHf/x horizontal movement of the sweeper (inches).
pfxCUO-XnumericPITCHf/x horizontal movement of the other curve (inches).
pfxCV-XnumericPITCHf/x horizontal movement of the curve (inches).
pfxFA-ZnumericPITCHf/x vertical movement of the four-seam fastball (inches).
pfxFC-ZnumericPITCHf/x vertical movement of the cutter (inches).
pfxFS-ZnumericPITCHf/x vertical movement of the splitter (inches).
pfxFO-ZnumericPITCHf/x vertical movement of the forkball (inches).
pfxSI-ZnumericPITCHf/x vertical movement of the sinker (inches).
pfxSL-ZnumericPITCHf/x vertical movement of the slider (inches).
pfxCU-ZnumericPITCHf/x vertical movement of the curveball (inches).
pfxKC-ZnumericPITCHf/x vertical movement of the knuckle curve (inches).
pfxCH-ZnumericPITCHf/x vertical movement of the changeup (inches).
pfxSLO-ZnumericPITCHf/x vertical movement of the slurve (inches).
pfxST-ZnumericPITCHf/x vertical movement of the sweeper (inches).
pfxCUO-ZnumericPITCHf/x vertical movement of the other curve (inches).
pfxCV-ZnumericPITCHf/x vertical movement of the curve (inches).
pfxwFAnumericPITCHf/x total runs above average on the four-seam fastball.
pfxwFCnumericPITCHf/x total runs above average on the cutter.
pfxwFSnumericPITCHf/x total runs above average on the splitter.
pfxwFOnumericPITCHf/x total runs above average on the forkball.
pfxwSInumericPITCHf/x total runs above average on the sinker.
pfxwSLnumericPITCHf/x total runs above average on the slider.
pfxwCUnumericPITCHf/x total runs above average on the curveball.
pfxwKCnumericPITCHf/x total runs above average on the knuckle curve.
pfxwCHnumericPITCHf/x total runs above average on the changeup.
pfxwSLOnumericPITCHf/x total runs above average on the slurve.
pfxwSTnumericPITCHf/x total runs above average on the sweeper.
pfxwCUOnumericPITCHf/x total runs above average on the other curve.
pfxwCVnumericPITCHf/x total runs above average on the curve.
pfxwFA/CnumericPITCHf/x runs above average per 100 four-seam fastballs.
pfxwFC/CnumericPITCHf/x runs above average per 100 cutters.
pfxwFS/CnumericPITCHf/x runs above average per 100 splitters.
pfxwFO/CnumericPITCHf/x runs above average per 100 forkballs.
pfxwSI/CnumericPITCHf/x runs above average per 100 sinkers.
pfxwSL/CnumericPITCHf/x runs above average per 100 sliders.
pfxwCU/CnumericPITCHf/x runs above average per 100 curveballs.
pfxwKC/CnumericPITCHf/x runs above average per 100 knuckle curves.
pfxwCH/CnumericPITCHf/x runs above average per 100 changeups.
pfxwSLO/CnumericPITCHf/x runs above average per 100 slurves.
pfxwST/CnumericPITCHf/x runs above average per 100 sweepers.
pfxwCUO/CnumericPITCHf/x runs above average per 100 other curves.
pfxwCV/CnumericPITCHf/x runs above average per 100 curves.
pfxaaFAnumericPITCHf/x average spin/active component on the four-seam fastball.
pfxaaFCnumericPITCHf/x average spin/active component on the cutter.
pfxaaFSnumericPITCHf/x average spin/active component on the splitter.
pfxaaFOnumericPITCHf/x average spin/active component on the forkball.
pfxaaSInumericPITCHf/x average spin/active component on the sinker.
pfxaaSLnumericPITCHf/x average spin/active component on the slider.
pfxaaCUnumericPITCHf/x average spin/active component on the curveball.
pfxaaKCnumericPITCHf/x average spin/active component on the knuckle curve.
pfxaaCHnumericPITCHf/x average spin/active component on the changeup.
pfxaaSLOnumericPITCHf/x average spin/active component on the slurve.
pfxaaSTnumericPITCHf/x average spin/active component on the sweeper.
pfxaaCUOnumericPITCHf/x average spin/active component on the other curve.
pfxaaCVnumericPITCHf/x average spin/active component on the curve.
pfxspFAnumericPITCHf/x average spin rate on the four-seam fastball (rpm).
pfxspFCnumericPITCHf/x average spin rate on the cutter (rpm).
pfxspFSnumericPITCHf/x average spin rate on the splitter (rpm).
pfxspFOnumericPITCHf/x average spin rate on the forkball (rpm).
pfxspSInumericPITCHf/x average spin rate on the sinker (rpm).
pfxspSLnumericPITCHf/x average spin rate on the slider (rpm).
pfxspCUnumericPITCHf/x average spin rate on the curveball (rpm).
pfxspKCnumericPITCHf/x average spin rate on the knuckle curve (rpm).
pfxspCHnumericPITCHf/x average spin rate on the changeup (rpm).
pfxspSLOnumericPITCHf/x average spin rate on the slurve (rpm).
pfxspSTnumericPITCHf/x average spin rate on the sweeper (rpm).
pfxspCUOnumericPITCHf/x average spin rate on the other curve (rpm).
pfxspCVnumericPITCHf/x average spin rate on the curve (rpm).
pfxO-Swing%numericPITCHf/x Swing rate on pitches outside the zone.
pfxZ-Swing%numericPITCHf/x Swing rate on pitches in the zone.
pfxSwing%numericPITCHf/x Overall swing rate.
pfxO-Contact%numericPITCHf/x Contact rate on pitches outside the zone.
pfxZ-Contact%numericPITCHf/x Contact rate on pitches in the zone.
pfxContact%numericPITCHf/x Overall contact rate.
pfxZone%numericPITCHf/x Rate of pitches in the strike zone.
pfxPacenumericPITCHf/x Average seconds between pitches.
AvgBatSpeednumericAverage bat speed (mph).
FastSwing%numericRate of fast swings.
SwingLengthnumericAverage swing length (feet).
SquaredUpContact%numericSquared-up rate per contact.
SquaredUpSwing%numericSquared-up rate per swing.
BlastContact%numericBlast rate per contact.
BlastSwing%numericBlast rate per swing.
SwordsnumericSwords (especially ugly swinging strikeouts).
CompetitiveSwingsnumericCompetitive swings.
TiltnumericAverage swing tilt (degrees).
AttackAnglenumericAverage attack angle (degrees).
AttackDirectionnumericAverage attack direction (degrees).
IdealAttackAngle%numericRate of swings in the ideal attack-angle range.
DepthInBoxnumericAverage depth in the batter's box (inches).
DistanceOffPlatenumericAverage distance off the plate (inches).
scH-Swing%numericStatcast heart-zone swing rate.
scH-Contact%numericStatcast heart-zone contact rate.
scH-Zone%numericStatcast heart-zone zone rate.
scS-Swing%numericStatcast shadow-zone swing rate.
scS-Contact%numericStatcast shadow-zone contact rate.
scS-Zone%numericStatcast shadow-zone zone rate.
scC-Swing%numericStatcast chase-zone swing rate.
scC-Contact%numericStatcast chase-zone contact rate.
scC-Zone%numericStatcast chase-zone zone rate.
scW-Swing%numericStatcast waste-zone swing rate.
scW-Contact%numericStatcast waste-zone contact rate.
scW-Zone%numericStatcast waste-zone zone rate.
scSI-Swing%numericStatcast in-zone strike-zone swing rate.
scSI-Contact%numericStatcast in-zone strike-zone contact rate.
scSI-Zone%numericStatcast in-zone strike-zone zone rate.
scSO-Swing%numericStatcast out-of-zone strike-zone swing rate.
scSO-Contact%numericStatcast out-of-zone strike-zone contact rate.
scSO-Zone%numericStatcast out-of-zone strike-zone zone rate.
scO-Swing%numericStatcast out-of-zone-zone swing rate.
scO-Contact%numericStatcast out-of-zone-zone contact rate.
scO-Zone%numericStatcast out-of-zone-zone zone rate.
scZ-Swing%numericStatcast in-zone-zone swing rate.
scZ-Contact%numericStatcast in-zone-zone contact rate.
scZ-Zone%numericStatcast in-zone-zone zone rate.
piCH%numericPITCHInfo changeup usage rate.
piCS%numericPITCHInfo slow curve usage rate.
piCU%numericPITCHInfo curveball usage rate.
piFA%numericPITCHInfo four-seam fastball usage rate.
piFC%numericPITCHInfo cutter usage rate.
piFS%numericPITCHInfo splitter usage rate.
piSI%numericPITCHInfo sinker usage rate.
piSL%numericPITCHInfo slider usage rate.
piXX%numericPITCHInfo unknown/other pitch usage rate.
pivCHnumericPITCHInfo average changeup velocity (mph).
pivCSnumericPITCHInfo average slow curve velocity (mph).
pivCUnumericPITCHInfo average curveball velocity (mph).
pivFAnumericPITCHInfo average four-seam fastball velocity (mph).
pivFCnumericPITCHInfo average cutter velocity (mph).
pivFSnumericPITCHInfo average splitter velocity (mph).
pivSInumericPITCHInfo average sinker velocity (mph).
pivSLnumericPITCHInfo average slider velocity (mph).
pivXXnumericPITCHInfo average unknown/other pitch velocity (mph).
piCH-XnumericPITCHInfo horizontal movement of the changeup (inches).
piCS-XnumericPITCHInfo horizontal movement of the slow curve (inches).
piCU-XnumericPITCHInfo horizontal movement of the curveball (inches).
piFA-XnumericPITCHInfo horizontal movement of the four-seam fastball (inches).
piFC-XnumericPITCHInfo horizontal movement of the cutter (inches).
piFS-XnumericPITCHInfo horizontal movement of the splitter (inches).
piSI-XnumericPITCHInfo horizontal movement of the sinker (inches).
piSL-XnumericPITCHInfo horizontal movement of the slider (inches).
piXX-XnumericPITCHInfo horizontal movement of the unknown/other pitch (inches).
piCH-ZnumericPITCHInfo vertical movement of the changeup (inches).
piCS-ZnumericPITCHInfo vertical movement of the slow curve (inches).
piCU-ZnumericPITCHInfo vertical movement of the curveball (inches).
piFA-ZnumericPITCHInfo vertical movement of the four-seam fastball (inches).
piFC-ZnumericPITCHInfo vertical movement of the cutter (inches).
piFS-ZnumericPITCHInfo vertical movement of the splitter (inches).
piSI-ZnumericPITCHInfo vertical movement of the sinker (inches).
piSL-ZnumericPITCHInfo vertical movement of the slider (inches).
piXX-ZnumericPITCHInfo vertical movement of the unknown/other pitch (inches).
piwCHnumericPITCHInfo total runs above average on the changeup.
piwCSnumericPITCHInfo total runs above average on the slow curve.
piwCUnumericPITCHInfo total runs above average on the curveball.
piwFAnumericPITCHInfo total runs above average on the four-seam fastball.
piwFCnumericPITCHInfo total runs above average on the cutter.
piwFSnumericPITCHInfo total runs above average on the splitter.
piwSInumericPITCHInfo total runs above average on the sinker.
piwSLnumericPITCHInfo total runs above average on the slider.
piwXXnumericPITCHInfo total runs above average on the unknown/other pitch.
piwCH/CnumericPITCHInfo runs above average per 100 changeups.
piwCS/CnumericPITCHInfo runs above average per 100 slow curves.
piwCU/CnumericPITCHInfo runs above average per 100 curveballs.
piwFA/CnumericPITCHInfo runs above average per 100 four-seam fastballs.
piwFC/CnumericPITCHInfo runs above average per 100 cutters.
piwFS/CnumericPITCHInfo runs above average per 100 splitters.
piwSI/CnumericPITCHInfo runs above average per 100 sinkers.
piwSL/CnumericPITCHInfo runs above average per 100 sliders.
piwXX/CnumericPITCHInfo runs above average per 100 unknown/other pitchs.
piO-Swing%numericPITCHInfo Swing rate on pitches outside the zone.
piZ-Swing%numericPITCHInfo Swing rate on pitches in the zone.
piSwing%numericPITCHInfo Overall swing rate.
piO-Contact%numericPITCHInfo Contact rate on pitches outside the zone.
piZ-Contact%numericPITCHInfo Contact rate on pitches in the zone.
piContact%numericPITCHInfo Overall contact rate.
piZone%numericPITCHInfo Rate of pitches in the strike zone.
EventsnumericBatted-ball events with Statcast data.
EVnumericAverage exit velocity (mph).
LAnumericAverage launch angle (degrees).
BarrelsnumericBarreled batted balls.
Barrel%numericBarrel rate (per batted-ball event).
maxEVnumericMaximum exit velocity (mph).
HardHitnumericHard-hit batted balls (95+ mph).
HardHit%numericHard-hit rate (95+ mph).
gamedatecharacterGame date as parsed from the source feed.
dhintegerDoubleheader game indicator (0 = single game).

Examples

# \donttest{
  try(fg_batter_game_logs(playerid = 19755, year = 2023))
#> ── MLB Batter Game Logs data from FanGraphs.com ───── baseballr 2.0.0 ──
#>  Data updated: 2026-06-09 20:42:45 UTC
#> # A tibble: 135 × 342
#>    PlayerName    playerid Date   Team  Opp   season   Age BatOrder Pos  
#>    <chr>            <int> <chr>  <chr> <chr>  <int> <int> <chr>    <chr>
#>  1 Shohei Ohtani    19755 2023-… LAA   @OAK    2023    28 2        DH   
#>  2 Shohei Ohtani    19755 2023-… LAA   @OAK    2023    28 2        DH   
#>  3 Shohei Ohtani    19755 2023-… LAA   @OAK    2023    28 3        DH   
#>  4 Shohei Ohtani    19755 2023-… LAA   @PHI    2023    28 3        DH   
#>  5 Shohei Ohtani    19755 2023-… LAA   @PHI    2023    28 2        DH   
#>  6 Shohei Ohtani    19755 2023-… LAA   @PHI    2023    28 2        DH   
#>  7 Shohei Ohtani    19755 2023-… LAA   @NYM    2023    28 2        DH   
#>  8 Shohei Ohtani    19755 2023-… LAA   @NYM    2023    28 2        DH   
#>  9 Shohei Ohtani    19755 2023-… LAA   @NYM    2023    28 2        DH   
#> 10 Shohei Ohtani    19755 2023-… LAA   CIN     2023    28 2        DH   
#> # ℹ 125 more rows
#> # ℹ 333 more variables: G <dbl>, AB <dbl>, PA <dbl>, H <dbl>,
#> #   `1B` <dbl>, `2B` <dbl>, `3B` <dbl>, HR <dbl>, R <dbl>, RBI <dbl>,
#> #   BB <dbl>, IBB <dbl>, SO <dbl>, HBP <dbl>, SF <dbl>, SH <dbl>,
#> #   GDP <dbl>, SB <dbl>, CS <dbl>, AVG <dbl>, GB <dbl>, FB <dbl>,
#> #   LD <dbl>, IFFB <dbl>, Pitches <dbl>, Balls <dbl>, Strikes <dbl>,
#> #   IFH <dbl>, BU <dbl>, BUH <dbl>, `BB%` <dbl>, `K%` <dbl>, …
# }