mlbstatsR

library(mlbstatsR)

mlbstatsR es un package que tiene como objetivo facilitar las estadisticas, fotos de los jugadores, los logos y los colores de los equipos de la liga profesional de Baseball MLB, para visualizaciones y graficas

Que contiene el package

El package contiene las siguientes funciones:

Algunos Ejemplos

get_reference_players_mlb()

Descarga de la página baseball-reference desde el año 1876 las estadsiticas de los jugadores en Batting Pitching y Fielding.

En Batting podemos seleccionar standard, advanced, value, probability, ratio, baserunning, pitchesbatting, neutralizedbatting, situational, baserunning, cumulative . Como por ejemplo :

get_reference_players_mlb(1945, “batting”, “value”)

#> LOADING 1945 batting value from the index:
#> 'advanced', 'value', 'probability', 'ratio', 'baserunning', 'standard'
#> 'pitchesbatting', 'neutralizedbatting','situational', 'baserunning' o 'cumulative'
#> # A tibble: 547 x 27
#>     year stats stats_type rk    name  age   tm    g     pa    rbat  rbaser rdp  
#>    <dbl> <chr> <chr>      <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>  <chr>
#>  1  1945 batt… value      1     Ace … 35    NYG   65    20    -2    0      0    
#>  2  1945 batt… value      2     Bust… 30    2TM   154   707   15    0      1    
#>  3  1945 batt… value      3     Morr… 29    2TM   70    174   -1    -1     1    
#>  4  1945 batt… value      4     Nate… 31    BSN   22    53    -5    0      0    
#>  5  1945 batt… value      5     Stan… 28    2TM   34    89    -4    1      0    
#>  6  1945 batt… value      6     John… 29    2TM   127   540   -16   -2     -1   
#>  7  1945 batt… value      7     Pete… 41    2TM   8     5     0     0      0    
#>  8  1945 batt… value      8     Luke… 38    CHW   18    70    7     0      0    
#>  9  1945 batt… value      9     Joe … 22    PHA   10    18    -3    0      0    
#> 10  1945 batt… value      10    Jim … 28    CLE   25    61    -1    0      0    
#> # … with 537 more rows, and 15 more variables: rfield <chr>, rpos <chr>,
#> #   raa <chr>, waa <chr>, rrep <chr>, rar <chr>, war <chr>,
#> #   waa_wl_percent <chr>, x162wl_percent <chr>, o_war <chr>, d_war <chr>,
#> #   o_rar <chr>, salary <chr>, acquired <chr>, pos_summary <chr>

En Pitching podemos seleccionar advanced, value, probability, ratio, battingagainst, startingpitching, standard, reliefpitching, neutralizedpitching, baserunning o cumulative. Como por ejemplo :

get_reference_players_mlb(1965, “pitching”, “ratio”)

#> LOADING 1965 pitching ratio from the index:
#> 'advanced', 'value', 'probability', 'ratio', 'battingagainst', 'startingpitching',
#> 'standard', 'reliefpitching', 'neutralizedpitching', 'baserunning' o 'cumulative'
#> # A tibble: 341 x 25
#>     year stats  stats_type rk    name   age   tm    ip    ptn_percent hr_percent
#>    <dbl> <chr>  <chr>      <chr> <chr>  <chr> <chr> <chr> <chr>       <chr>     
#>  1  1965 pitch… ratio      1     Ted A… 32    CHC   136.1 57%         1.2%      
#>  2  1965 pitch… ratio      2     Hank … 34    DET   208.1 19%         2.7%      
#>  3  1965 pitch… ratio      3     Jack … 24    KCA   51.1  59%         1.4%      
#>  4  1965 pitch… ratio      4     Matty… 26    SFG   2.0   30%         0.0%      
#>  5  1965 pitch… ratio      5     Don A… 22    HOU   6.0   35%         0.0%      
#>  6  1965 pitch… ratio      6     Gerry… 24    CIN   54.0  27%         1.5%      
#>  7  1965 pitch… ratio      7     Denni… 24    STL   7.1   58%         0.0%      
#>  8  1965 pitch… ratio      8     Jack … 28    PHI   99.0  61%         0.9%      
#>  9  1965 pitch… ratio      9     Steve… 27    BAL   220.2 20%         1.8%      
#> 10  1965 pitch… ratio      10    Ed Ba… 21    BAL   4.1   82%         0.0%      
#> # … with 331 more rows, and 15 more variables: so_percent <chr>,
#> #   bb_percent <chr>, so_bb_percent <chr>, xbh_percent <chr>,
#> #   x_h_percent <chr>, gb_fb <chr>, go_ao <chr>, ip_percent <chr>,
#> #   ld_percent <chr>, hr_fb <chr>, if_fb <chr>, opp <chr>, dp <chr>,
#> #   percent <chr>, p_au <chr>

En Fielding podemos seleccionar appearances, pitcher, catcher, firstbase, secondbase, thirdbase, shortstop, leftfield, centerfield, rightfield, outfield. Como por ejemplo :

get_reference_players_mlb(2002, “fielding”, “appearances”)

#> LOADING 2002 fielding appearances from the index:
#> 'appearances', 'pitcher', 'catcher', 'firstbase', 'secondbase', 'thirdbase',
#> 'shortstop', 'leftfield', 'centerfield', 'rightfield', 'outfield'
#> # A tibble: 1,218 x 25
#>     year stats  stats_type  rk    name     age   tm    yrs   g     gs    batting
#>    <dbl> <chr>  <chr>       <chr> <chr>    <chr> <chr> <chr> <chr> <chr> <chr>  
#>  1  2002 field… appearances 1     Paul Ab… 34    SEA   9     7     5     0      
#>  2  2002 field… appearances 2     Brent A… 24    TBD   2     117   115   117    
#>  3  2002 field… appearances 3     Bobby A… 28    PHI   7     157   153   157    
#>  4  2002 field… appearances 4     Jose Ac… 24    CIN   2     6     5     6      
#>  5  2002 field… appearances 5     Juan Ac… 32    DET   7     65    0     4      
#>  6  2002 field… appearances 6     Terry A… 29    PHI   8     46    19    45     
#>  7  2002 field… appearances 7     Jeremy … 23    KCR   1st   34    7     0      
#>  8  2002 field… appearances 8     Benny A… 30    2TM   5     61    41    61     
#>  9  2002 field… appearances 9     Kurt Ai… 23    SFG   2     6     4     6      
#> 10  2002 field… appearances 10    Israel … 29    MIL   3     16    6     16     
#> # … with 1,208 more rows, and 14 more variables: defense <chr>, p <chr>,
#> #   c <chr>, x1b <chr>, x2b <chr>, x3b <chr>, ss <chr>, lf <chr>, cf <chr>,
#> #   rf <chr>, of <chr>, dh <chr>, ph <chr>, pr <chr>

get_reference_team_mlb()

Descarga de la página baseball-reference desde el año 1876 las estadisticas de los equipos en Batting Pitching y Fielding.

En Batting podemos seleccionar standard, advanced, value, probability, ratio, baserunning, pitchesbatting, neutralizedbatting, situational. Como por ejemplo :

get_reference_team_mlb(2021,“batting”, “advanced”)

#> LOADING 2021 batting advanced from the index:
#> 'advanced', 'value', 'probability', 'ratio', 'baserunning',
#> 'standard', 'pitchesbatting', 'situational' o 'baserunning'
#> # A tibble: 33 x 26
#>     year stats stats_type tm    r_g   outs  rc    rc_g  air   b_abip ba    lg_ba
#>    <dbl> <chr> <chr>      <chr> <chr> <chr> <chr> <chr> <chr> <chr>  <chr> <chr>
#>  1  2021 batt… advanced   ARI   4.23  1772  279   4.1   99    .287   .232  .244 
#>  2  2021 batt… advanced   ATL   4.76  1635  298   4.8   105   .283   .235  .252 
#>  3  2021 batt… advanced   BAL   4.08  1657  262   4.2   96    .289   .239  .243 
#>  4  2021 batt… advanced   BOS   4.97  1698  312   4.8   99    .309   .255  .246 
#>  5  2021 batt… advanced   CHC   4.66  1692  292   4.5   93    .285   .235  .237 
#>  6  2021 batt… advanced   CHW   5.06  1632  308   5.0   94    .315   .254  .240 
#>  7  2021 batt… advanced   CIN   5.05  1669  312   4.9   108   .293   .250  .256 
#>  8  2021 batt… advanced   CLE   4.18  1607  242   4.0   99    .267   .226  .246 
#>  9  2021 batt… advanced   COL   4.26  1689  272   4.2   106   .300   .242  .254 
#> 10  2021 batt… advanced   DET   3.78  1692  244   3.8   94    .292   .226  .240 
#> # … with 23 more rows, and 14 more variables: obp <chr>, lg_obp <chr>,
#> #   slg <chr>, lg_slg <chr>, ops <chr>, lg_ops <chr>, ops_2 <chr>,
#> #   o_wn_percent <chr>, bt_runs <chr>, bt_wins <chr>, tot_a <chr>, sec_a <chr>,
#> #   iso <chr>, pwr_spd <chr>

En Pitching podemos seleccionar standard, batting, value, probability, ratio, battingagainst, startingpitching, reliefpitching, basesituation. Como por ejemplo:

get_reference_team_mlb(1980, “pitching”, “battingagainst”)

#> LOADING 1980 pitching battingagainst from the index:
#> 'batting', 'value', 'probability', 'ratio', 'battingagainst', 'startingpitching',
#> 'reliefpitching',  'basesituation', 'standard'
#> # A tibble: 29 x 30
#>     year stats  stats_type tm    ra_g  p_au  g     pa    ab    r     h     x2b  
#>    <dbl> <chr>  <chr>      <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#>  1  1980 pitch… batting    ATL   4.10  ""    161   6028  5423  660   1397  232  
#>  2  1980 pitch… batting    BAL   3.95  ""    162   6131  5510  640   1438  241  
#>  3  1980 pitch… batting    BOS   4.79  ""    160   6192  5571  767   1557  287  
#>  4  1980 pitch… batting    CAL   4.98  ""    160   6256  5563  797   1548  271  
#>  5  1980 pitch… batting    CHC   4.49  ""    162   6402  5613  728   1525  263  
#>  6  1980 pitch… batting    CHW   4.46  ""    162   6199  5448  722   1434  217  
#>  7  1980 pitch… batting    CIN   4.11  ""    163   6143  5511  670   1404  246  
#>  8  1980 pitch… batting    CLE   5.04  ""    160   6221  5531  807   1519  230  
#>  9  1980 pitch… batting    DET   4.64  ""    163   6335  5630  757   1505  252  
#> 10  1980 pitch… batting    HOU   3.61  ""    163   6160  5562  589   1367  203  
#> # … with 19 more rows, and 18 more variables: x3b <chr>, hr <chr>, sb <chr>,
#> #   cs <chr>, bb <chr>, so <chr>, ba <chr>, obp <chr>, slg <chr>, ops <chr>,
#> #   b_abip <chr>, tb <chr>, gdp <chr>, hbp <chr>, sh <chr>, sf <chr>,
#> #   ibb <chr>, roe <chr>

En Fielding podemos seleccionar standard, appearances, pitcher, catcher, firstbase, secondbase, thirdbase, shortstop, leftfield, centerfield, rightfield, outfield. Ejemplo:

get_reference_team_mlb(1980, “fielding”, “centerfield”)

#> LOADING 1980 fielding centerfield from the index:
#> 'appearances', 'pitcher', 'catcher', 'firstbase', 'secondbase', 'thirdbase',
#>          'shortstop', 'leftfield', 'centerfield', 'rightfield', 'outfield'
#> # A tibble: 29 x 20
#>     year stats  stats_type  tm    number_fld ra_g  g     gs    cg    inn   ch   
#>    <dbl> <chr>  <chr>       <chr> <chr>      <chr> <chr> <chr> <chr> <chr> <chr>
#>  1  1980 field… specialpos… ATL   5          4.10  161   161   150   1428… 412  
#>  2  1980 field… specialpos… BAL   2          3.95  162   162   154   1460… 524  
#>  3  1980 field… specialpos… BOS   7          4.79  160   160   146   1441… 457  
#>  4  1980 field… specialpos… CAL   4          4.98  160   160   134   1428… 504  
#>  5  1980 field… specialpos… CHC   6          4.49  162   162   129   1479… 424  
#>  6  1980 field… specialpos… CHW   5          4.46  162   162   149   1435… 450  
#>  7  1980 field… specialpos… CIN   6          4.11  163   163   74    1459… 474  
#>  8  1980 field… specialpos… CLE   6          5.04  160   160   143   1428… 466  
#>  9  1980 field… specialpos… DET   5          4.64  163   163   139   1467… 483  
#> 10  1980 field… specialpos… HOU   5          3.61  163   163   148   1482… 446  
#> # … with 19 more rows, and 9 more variables: po <chr>, a <chr>, e <chr>,
#> #   dp <chr>, fld_percent <chr>, rtot <chr>, rtot_yr <chr>, rtz <chr>,
#> #   rof <chr>

espn_player_stats()

Descarga de la pagina de ESPN las estadisticas de los jugadores de la MLB desde el año 2002. Podemos seleccionar Regular o Playoffs y las estadisticas de batting, pitching y fielding.

Regular

espn_player_stats(2015, “pitching”, “regular”)

#> Getting pitching stats de la regular season del 2015!
#> # A tibble: 78 x 23
#>     year season_type  rank name           team  pos   games_played games_started
#>    <dbl> <chr>       <int> <chr>          <chr> <chr>        <int>         <int>
#>  1  2015 regular         1 Zack Greinke   LAD   SP              32            32
#>  2  2015 regular         2 Jake Arrieta   CHC   SP              33            33
#>  3  2015 regular         3 Clayton Kersh… LAD   SP              33            33
#>  4  2015 regular         4 David Price    DET   SP              32            32
#>  5  2015 regular         5 Dallas Keuchel HOU   SP              33            33
#>  6  2015 regular         6 Jacob deGrom   NYM   SP              30            30
#>  7  2015 regular         7 Gerrit Cole    PIT   SP              32            32
#>  8  2015 regular         8 Matt Harvey    NYM   SP              29            29
#>  9  2015 regular         9 Sonny Gray     OAK   SP              31            31
#> 10  2015 regular        10 John Lackey    STL   SP              33            33
#> # … with 68 more rows, and 15 more variables: quality_starts <int>,
#> #   earned_run_avg <dbl>, wins <int>, losses <int>, saves <int>, holds <int>,
#> #   innings_pitched <dbl>, hits <int>, earned_runs <int>, home_runs <int>,
#> #   walks <int>, strikeouts <int>, strikes_x_9_i <dbl>, war <dbl>, whip <dbl>

Playoffs

espn_player_stats(2004, “batting”, “playoffs”)

#> Getting batting stats de los playoffs del 2004!
#> # A tibble: 61 x 23
#>     year season_type  rank name     team  pos   games_played at_bats  runs  hits
#>    <dbl> <chr>       <int> <chr>    <chr> <chr>        <int>   <int> <int> <int>
#>  1  2004 playoffs        1 Andruw … ATL   LF               5      19     4    10
#>  2  2004 playoffs        2 Darin E… ANA   LF               3      10     2     5
#>  3  2004 playoffs        3 Michael… MIN   LF               4      15     1     7
#>  4  2004 playoffs        4 Carlos … HOU   OF              12      46    21    20
#>  5  2004 playoffs        5 Albert … STL   1B              15      58    15    24
#>  6  2004 playoffs        6 Hideki … NYY   LF              11      51    12    21
#>  7  2004 playoffs        7 David O… BOS   DH              14      55    13    22
#>  8  2004 playoffs        8 Rafael … ATL   2B               5      21     5     8
#>  9  2004 playoffs        9 Troy Gl… ANA   1B               3      11     3     4
#> 10  2004 playoffs       10 Torii H… MIN   RF               4      17     5     6
#> # … with 51 more rows, and 13 more variables: batting_avg <dbl>, doubles <int>,
#> #   triples <int>, home_runs <int>, runs_batted_in <int>, total_bases <int>,
#> #   walks <int>, strikeouts <int>, stolen_bases <int>, on_base_pct <dbl>,
#> #   slugging_pct <dbl>, opb_slg_pct <dbl>, war <dbl>

espn_team_stats()

Descarga de la pagina de ESPN las estadisticas de los equipos de la MLB desde el año 2002. Podemos seleccionar Regular o Playoffs y las estadisticas de batting, pitching y fielding.

Regular

espn_team_stats(2021, “fielding”, “regular”)

#> Getting fielding stats de la regular season del 2021!
#> # A tibble: 30 x 10
#>     year season_type  rank team   g_played errors fielding_percen… total_chances
#>    <dbl> <chr>       <int> <chr>     <int>  <int>            <dbl> <chr>        
#>  1  2021 regular         1 Tampa…       65     25            0.99  2,390        
#>  2  2021 regular         2 Houst…       64     24            0.989 2,281        
#>  3  2021 regular         3 San F…       64     25            0.989 2,309        
#>  4  2021 regular         4 Balti…       63     30            0.986 2,159        
#>  5  2021 regular         5 Chica…       64     33            0.986 2,289        
#>  6  2021 regular         6 Oakla…       66     34            0.985 2,287        
#>  7  2021 regular         7 Texas…       65     36            0.985 2,361        
#>  8  2021 regular         8 Pitts…       63     31            0.984 1,994        
#>  9  2021 regular         9 New Y…       56     30            0.984 1,907        
#> 10  2021 regular        10 Washi…       61     33            0.984 2,068        
#> # … with 20 more rows, and 2 more variables: putouts <chr>, assists <int>

Playoffs

espn_team_stats(2011, “fielding”, “playoffs”)

#> Getting fielding stats de los playoffs del 2011!
#> # A tibble: 8 x 10
#>    year season_type  rank team    g_played errors fielding_percen… total_chances
#>   <dbl> <chr>       <int> <chr>      <int>  <int>            <dbl>         <int>
#> 1  2011 playoffs        1 Tampa …        4      0            0               143
#> 2  2011 playoffs        2 New Yo…        5      1            0.995           194
#> 3  2011 playoffs        3 Arizon…        5      1            0.994           164
#> 4  2011 playoffs        4 Detroi…       11      5            0.988           401
#> 5  2011 playoffs        5 St. Lo…       18     10            0.985           685
#> 6  2011 playoffs        6 Philad…        5      3            0.984           190
#> 7  2011 playoffs        7 Texas …       17     12            0.981           646
#> 8  2011 playoffs        8 Milwau…       11     12            0.971           408
#> # … with 2 more variables: putouts <int>, assists <int>

Espero que sea util