Skip to contents

This function allows you to scrape all leaderboard statistics (basic and advanced) from FanGraphs.com.

Usage

fg_fielder_leaders(
  age = "",
  pos = "all",
  stats = "fld",
  lg = "all",
  qual = "0",
  startseason = "2023",
  endseason = "2023",
  startdate = "",
  enddate = "",
  month = "0",
  hand = "",
  team = "0",
  pageitems = "10000",
  pagenum = "1",
  ind = "0",
  rost = "0",
  players = "",
  type = "1",
  postseason = "",
  sortdir = "default",
  sortstat = "Defense"
)

Arguments

age

(integer) Age of players

pos

(character) Position of players, defaults to "all". To exclude pitchers, use "np".

stats

(character) Statistic to return. Defaults to "bat".

lg

(character) League to return. Defaults to "all". Options are "al", "nl", or "all".

qual

(character) 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".

startseason

(character) Season for which you want to scrape the data.

endseason

(character) Last season for which you want data.

startdate

(character) Start date for which you want data.

enddate

(character) End date for which you want data.

month

(character) Month for which you want data.

hand

(character) Handedness of batter. Options are "L", "R", or "B". Empty string returns all.

team

(character) Teams for which you want data, comma separated.

pageitems

(character) Number of items per page.

pagenum

(character) Page number.

ind

(character) Whether or not to break the seasons out individual, or roll them up together. 1 = split seasons, 0 = aggregate seasons.

rost

(character) Whether or not to include players on the roster. 1 = include, 0 = exclude.

players

(character) Whether or not to include players on the roster. 1 = include only active roster players, 0 = exclude.

type

(character) Defaults to 8, which is the standard leaderboard. The values for the leaderboards appear to go to from type = 0 to 48+, which correspond to links on the leaderboard page.

postseason

(logical) Whether or not to include postseason data. TRUE = include postseason, FALSE = exclude postseason.

sortdir

(character) Sort direction. Options are "asc" or "desc" or "default".

sortstat

(character) Sort by stat. Default is "Defense".

Value

A data frame of fielder data.

col_nametypes
Seasoninteger
team_namecharacter
xMLBAMIDinteger
PlayerNameRoutecharacter
PlayerNamecharacter
playeridinteger
SeasonMininteger
SeasonMaxinteger
Poscharacter
Ginteger
GSinteger
Innnumeric
POinteger
Ainteger
Einteger
FEinteger
TEinteger
DPinteger
DPSinteger
DPTinteger
DPFinteger
SBinteger
CSinteger
PBinteger
WPinteger
FPnumeric
rSBinteger
rGFPinteger
rSZnumeric
rCERAinteger
DRSinteger
Defensenumeric
CStrikesnumeric
CFramingnumeric
Qnumeric
TInnnumeric
teamidinteger
team_name_abbcharacter
rARMinteger
rPMinteger
BIZinteger
Playsinteger
RZRnumeric
OOZinteger
ARMnumeric
RngRnumeric
ErrRnumeric
UZRnumeric
UZR_150numeric
OAAinteger
rFRPinteger
rGDPinteger
DPRnumeric
Scpinteger

Examples

# \donttest{
  try(fg_fielder_leaders(startseason = 2023, endseason = 2023))
#> ── MLB Player Fielding Leaders data from FanGraphs.com ─────────────────
#>  Data updated: 2024-04-13 21:55:03 UTC
#> # A tibble: 2,293 × 59
#>    Season team_name xMLBAMID PlayerNameRoute   PlayerName       playerid
#>     <int> <chr>        <int> <chr>             <chr>               <int>
#>  1   2023 SFG         672275 Patrick Bailey    Patrick Bailey      27478
#>  2   2023 - - -       595978 Austin Hedges     Austin Hedges       12976
#>  3   2023 MIL         661388 William Contreras William Contrer…    20503
#>  4   2023 NYM         682626 Francisco Alvarez Francisco Alvar…    26121
#>  5   2023 TEX         641680 Jonah Heim        Jonah Heim          16930
#>  6   2023 CHC         621020 Dansby Swanson    Dansby Swanson      18314
#>  7   2023 ATL         669221 Sean Murphy       Sean Murphy         19352
#>  8   2023 TOR         672386 Alejandro Kirk    Alejandro Kirk      22581
#>  9   2023 SEA         663728 Cal Raleigh       Cal Raleigh         21534
#> 10   2023 COL         678662 Ezequiel Tovar    Ezequiel Tovar      24064
#> # ℹ 2,283 more rows
#> # ℹ 53 more variables: SeasonMin <int>, SeasonMax <int>, Pos <chr>,
#> #   G <int>, GS <int>, Inn <dbl>, PO <int>, A <int>, E <int>, FE <int>,
#> #   TE <int>, DP <int>, DPS <int>, DPT <int>, DPF <int>, SB <int>,
#> #   CS <int>, PB <int>, WP <int>, FP <dbl>, rSB <int>, rGFP <int>,
#> #   rSZ <dbl>, rCERA <int>, DRS <int>, Defense <dbl>, CStrikes <dbl>,
#> #   CFraming <dbl>, bFRP <int>, tFRP <int>, fFRP <int>, FRP <int>, …
# }