This function allows you to scrape all leaderboard statistics (basic and advanced) from FanGraphs.com.
Arguments
- x
First season for which you want data.
- y
Last season for which you want data. If multiple years selected, data returned will be aggregate data for the date range. If y = x, function will return single-season data.
- league
Option for limiting results to different leagues or overall results. Options are "al", "nl", or "all".
- qual
Whether you want only batters/pitchers that qualified in a given season, or the minimum number of plate appearances for inclusion. If you only want qualified hitters, use qual. If a minimum number of plate appearaces/innings pitched, use the number desired. Defaults to "y".
- ind
Whether or not to break the seasons out individual, or roll them up together. 1 = split seasons, 0 = aggregate seasons.
- exc_p
(logical) Whether or not to exclude pitchers from the batter leaderboards. TRUE = exclude pitchers, FALSE = retain pitchers.
Value
A data frame of batter data.
| col_name | types |
| playerid | character |
| # | character |
| Season | character |
| Name | character |
| Team | character |
| Age | numeric |
| G | numeric |
| AB | numeric |
| PA | numeric |
| H | numeric |
| 1B | numeric |
| 2B | numeric |
| 3B | numeric |
| HR | numeric |
| R | numeric |
| RBI | numeric |
| BB | numeric |
| IBB | numeric |
| SO | numeric |
| HBP | numeric |
| SF | numeric |
| SH | numeric |
| GDP | numeric |
| SB | numeric |
| CS | numeric |
| AVG | numeric |
| GB | numeric |
| FB | numeric |
| LD | numeric |
| IFFB | numeric |
| Pitches | numeric |
| Balls | numeric |
| Strikes | numeric |
| IFH | numeric |
| BU | numeric |
| BUH | numeric |
| BB_pct | numeric |
| K_pct | numeric |
| BB_K | numeric |
| OBP | numeric |
| SLG | numeric |
| OPS | numeric |
| ISO | numeric |
| BABIP | numeric |
| GB_FB | numeric |
| LD_pct | numeric |
| GB_pct | numeric |
| FB_pct | numeric |
| IFFB_pct | numeric |
| HR_FB | numeric |
| IFH_pct | numeric |
| BUH_pct | numeric |
| wOBA | numeric |
| wRAA | numeric |
| wRC | numeric |
| Bat | numeric |
| Fld | numeric |
| Rep | numeric |
| Pos | numeric |
| RAR | numeric |
| WAR | numeric |
| Dol | numeric |
| Spd | numeric |
| wRC_plus | numeric |
| WPA | numeric |
| WPA_minus | numeric |
| WPA_plus | numeric |
| RE24 | numeric |
| REW | numeric |
| pLI | numeric |
| phLI | numeric |
| PH | numeric |
| WPA_LI | numeric |
| Clutch | numeric |
| FBall_pct | numeric |
| FBv | numeric |
| SL_pct | numeric |
| SLv | numeric |
| CT_pct | numeric |
| CTv | numeric |
| CB_pct | numeric |
| CBv | numeric |
| CH_pct | numeric |
| CHv | numeric |
| SF_pct | numeric |
| SFv | numeric |
| KN_pct | numeric |
| KNv | numeric |
| XX_pct | numeric |
| PO_pct | numeric |
| wFB | numeric |
| wSL | numeric |
| wCT | numeric |
| wCB | numeric |
| wCH | numeric |
| wSF | numeric |
| wKN | numeric |
| wFB_C | numeric |
| wSL_C | numeric |
| wCT_C | numeric |
| wCB_C | numeric |
| wCH_C | numeric |
| wSF_C | numeric |
| wKN_C | numeric |
| O-Swing_pct | numeric |
| Z-Swing_pct | numeric |
| Swing_pct | numeric |
| O-Contact_pct | numeric |
| Z-Contact_pct | numeric |
| Contact_pct | numeric |
| Zone_pct | numeric |
| F-Strike_pct | numeric |
| SwStr_pct | numeric |
| BsR | numeric |
| FA_pct (sc) | numeric |
| FT_pct (sc) | numeric |
| FC_pct (sc) | numeric |
| FS_pct (sc) | numeric |
| FO_pct (sc) | numeric |
| SI_pct (sc) | numeric |
| SL_pct (sc) | numeric |
| CU_pct (sc) | numeric |
| KC_pct (sc) | numeric |
| EP_pct (sc) | numeric |
| CH_pct (sc) | numeric |
| SC_pct (sc) | numeric |
| KN_pct (sc) | numeric |
| UN_pct (sc) | numeric |
| vFA (sc) | numeric |
| vFT (sc) | numeric |
| vFC (sc) | numeric |
| vFS (sc) | numeric |
| vFO (sc) | numeric |
| vSI (sc) | numeric |
| vSL (sc) | numeric |
| vCU (sc) | numeric |
| vKC (sc) | numeric |
| vEP (sc) | numeric |
| vCH (sc) | numeric |
| vSC (sc) | numeric |
| vKN (sc) | numeric |
| FA-X (sc) | numeric |
| FT-X (sc) | numeric |
| FC-X (sc) | numeric |
| FS-X (sc) | numeric |
| FO-X (sc) | numeric |
| SI-X (sc) | numeric |
| SL-X (sc) | numeric |
| CU-X (sc) | numeric |
| KC-X (sc) | numeric |
| EP-X (sc) | numeric |
| CH-X (sc) | numeric |
| SC-X (sc) | numeric |
| KN-X (sc) | numeric |
| FA-Z (sc) | numeric |
| FT-Z (sc) | numeric |
| FC-Z (sc) | numeric |
| FS-Z (sc) | numeric |
| FO-Z (sc) | numeric |
| SI-Z (sc) | numeric |
| SL-Z (sc) | numeric |
| CU-Z (sc) | numeric |
| KC-Z (sc) | numeric |
| EP-Z (sc) | numeric |
| CH-Z (sc) | numeric |
| SC-Z (sc) | numeric |
| KN-Z (sc) | numeric |
| wFA (sc) | numeric |
| wFT (sc) | numeric |
| wFC (sc) | numeric |
| wFS (sc) | numeric |
| wFO (sc) | numeric |
| wSI (sc) | numeric |
| wSL (sc) | numeric |
| wCU (sc) | numeric |
| wKC (sc) | numeric |
| wEP (sc) | numeric |
| wCH (sc) | numeric |
| wSC (sc) | numeric |
| wKN (sc) | numeric |
| wFA_C (sc) | numeric |
| wFT_C (sc) | numeric |
| wFC_C (sc) | numeric |
| wFS_C (sc) | numeric |
| wFO_C (sc) | numeric |
| wSI_C (sc) | numeric |
| wSL_C (sc) | numeric |
| wCU_C (sc) | numeric |
| wKC_C (sc) | numeric |
| wEP_C (sc) | numeric |
| wCH_C (sc) | numeric |
| wSC_C (sc) | numeric |
| wKN_C (sc) | numeric |
| O-Swing_pct (sc) | numeric |
| Z-Swing_pct (sc) | numeric |
| Swing_pct (sc) | numeric |
| O-Contact_pct (sc) | numeric |
| Z-Contact_pct (sc) | numeric |
| Contact_pct (sc) | numeric |
| Zone_pct (sc) | numeric |
| Pace | numeric |
| Def | numeric |
| wSB | numeric |
| UBR | numeric |
| AgeRng | numeric |
| Off | numeric |
| Lg | numeric |
| wGDP | numeric |
| Pull_pct | numeric |
| Cent_pct | numeric |
| Oppo_pct | numeric |
| Soft_pct | numeric |
| Med_pct | numeric |
| Hard_pct | numeric |
| TTO_pct | numeric |
| CH_pct_pi | numeric |
| CS_pct_pi | numeric |
| CU_pct_pi | numeric |
| FA_pct_pi | numeric |
| FC_pct_pi | numeric |
| FS_pct_pi | numeric |
| KN_pct_pi | numeric |
| SB_pct_pi | numeric |
| SI_pct_pi | numeric |
| SL_pct_pi | numeric |
| XX_pct_pi | numeric |
| vCH_pi | numeric |
| vCS_pi | numeric |
| vCU_pi | numeric |
| vFA_pi | numeric |
| vFC_pi | numeric |
| vFS_pi | numeric |
| vKN_pi | numeric |
| vSB_pi | numeric |
| vSI_pi | numeric |
| vSL_pi | numeric |
| vXX_pi | numeric |
| CH-X_pi | numeric |
| CS-X_pi | numeric |
| CU-X_pi | numeric |
| FA-X_pi | numeric |
| FC-X_pi | numeric |
| FS-X_pi | numeric |
| KN-X_pi | numeric |
| SB-X_pi | numeric |
| SI-X_pi | numeric |
| SL-X_pi | numeric |
| XX-X_pi | numeric |
| CH-Z_pi | numeric |
| CS-Z_pi | numeric |
| CU-Z_pi | numeric |
| FA-Z_pi | numeric |
| FC-Z_pi | numeric |
| FS-Z_pi | numeric |
| KN-Z_pi | numeric |
| SB-Z_pi | numeric |
| SI-Z_pi | numeric |
| SL-Z_pi | numeric |
| XX-Z_pi | numeric |
| wCH_pi | numeric |
| wCS_pi | numeric |
| wCU_pi | numeric |
| wFA_pi | numeric |
| wFC_pi | numeric |
| wFS_pi | numeric |
| wKN_pi | numeric |
| wSB_pi | numeric |
| wSI_pi | numeric |
| wSL_pi | numeric |
| wXX_pi | numeric |
| wCH_C_pi | numeric |
| wCS_C_pi | numeric |
| wCU_C_pi | numeric |
| wFA_C_pi | numeric |
| wFC_C_pi | numeric |
| wFS_C_pi | numeric |
| wKN_C_pi | numeric |
| wSB_C_pi | numeric |
| wSI_C_pi | numeric |
| wSL_C_pi | numeric |
| wXX_C_pi | numeric |
| O-Swing_pct_pi | numeric |
| Z-Swing_pct_pi | numeric |
| Swing_pct_pi | numeric |
| O-Contact_pct_pi | numeric |
| Z-Contact_pct_pi | numeric |
| Contact_pct_pi | numeric |
| Zone_pct_pi | numeric |
| Pace_pi | numeric |
Examples
# \donttest{
try(fg_batter_leaders(x = 2015, y = 2015, qual = 400))
#> ── MLB Batter Leaders data from FanGraphs.com ─────── baseballr 1.2.0 ──
#> ℹ Data updated: 2022-04-30 07:15:13 UTC
#> # A tibble: 211 × 289
#> playerid `#` Season Name Team Age G AB PA H `1B`
#> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 11579 1 2015 Bryc… WSN 22 153 521 654 172 91
#> 2 4314 2 2015 Joey… CIN 31 158 545 695 171 107
#> 3 9218 3 2015 Paul… ARI 27 159 567 695 182 109
#> 4 10155 4 2015 Mike… LAA 23 159 575 682 172 93
#> 5 1744 5 2015 Migu… DET 32 119 429 511 145 98
#> 6 5038 6 2015 Josh… TOR 29 158 620 711 184 100
#> 7 2434 7 2015 Nels… SEA 34 152 590 655 178 111
#> 8 2151 8 2015 Edwi… TOR 32 146 528 624 146 76
#> 9 9272 9 2015 Chri… BAL 29 160 573 670 150 72
#> 10 1887 10 2015 Jose… TOR 34 153 543 666 136 64
#> # … with 201 more rows, and 278 more variables: `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_pct <dbl>, K_pct <dbl>, BB_K <dbl>, OBP <dbl>, SLG <dbl>,
#> # OPS <dbl>, ISO <dbl>, BABIP <dbl>, GB_FB <dbl>, LD_pct <dbl>, …
# }
