Welcome to the ballr [baw-ler], as in baller1. This is the R resource for your basketball-reference.com needs.
Current standings
## $East
## eastern_conference w l w_lpercent gb pw pl ps_g pa_g
## 1 Milwaukee Bucks 33 6 0.825 — 33 7 116.0 104.4
## 2 Miami Heat 27 10 0.711 5.0 24 14 108.5 104.5
## 3 Boston Celtics 25 11 0.694 6.5 25 11 110.6 104.4
## 4 Toronto Raptors 25 13 0.658 7.5 25 13 110.5 105.2
## 5 Philadelphia 76ers 25 14 0.641 8.0 24 15 109.8 105.7
## 6 Indiana Pacers 23 15 0.590 9.5 23 16 106.6 103.8
## 7 Orlando Magic 18 20 0.462 14.5 20 19 101.1 100.8
## 8 Brooklyn Nets 16 20 0.432 15.5 16 21 106.6 108.6
## 9 Charlotte Hornets 15 25 0.366 18.5 12 29 102.0 108.3
## 10 Detroit Pistons 14 25 0.359 19.0 16 23 108.5 111.2
## 11 Chicago Bulls 13 25 0.333 19.5 17 22 103.1 104.9
## 12 Washington Wizards 12 25 0.316 20.0 13 25 111.9 117.0
## 13 Cleveland Cavaliers 11 27 0.289 21.5 9 29 104.9 113.6
## 14 New York Knicks 10 28 0.256 22.5 10 29 101.5 109.5
## 15 Atlanta Hawks 8 30 0.205 24.5 9 30 105.0 114.4
##
## $West
## western_conference w l w_lpercent gb pw pl ps_g pa_g
## 1 Los Angeles Lakers 30 7 0.789 — 28 10 109.8 102.1
## 2 Denver Nuggets 26 11 0.703 4.0 23 14 109.1 105.2
## 3 Los Angeles Clippers 26 12 0.667 4.5 26 13 112.8 106.9
## 4 Houston Rockets 25 12 0.676 5.0 24 13 118.7 113.9
## 5 Utah Jazz 25 12 0.658 5.0 23 15 106.1 103.1
## 6 Dallas Mavericks 23 14 0.605 7.0 27 11 113.3 106.3
## 7 Oklahoma City Thunder 22 16 0.579 8.5 21 17 108.9 106.9
## 8 San Antonio Spurs 16 20 0.432 13.5 18 19 110.9 111.7
## 9 Memphis Grizzlies 16 22 0.410 14.5 15 24 109.7 113.3
## 10 Portland Trail Blazers 16 23 0.410 15.0 17 22 111.7 113.6
## 11 Minnesota Timberwolves 15 22 0.405 15.0 16 21 111.9 114.1
## 12 Sacramento Kings 15 23 0.385 15.5 17 22 103.5 105.7
## 13 Phoenix Suns 14 23 0.368 16.0 18 20 110.9 112.1
## 14 New Orleans Pelicans 13 25 0.333 17.5 15 24 110.2 113.7
## 15 Golden State Warriors 9 30 0.225 22.0 11 29 102.3 110.0
Standings on an arbitrary date
## $East
## eastern_conference w l w_lpercent gb pw pl ps_g pa_g
## 1 Cleveland Cavaliers* 21 9 0.700 — 20 10 99.7 95.1
## 2 Atlanta Hawks* 21 13 0.618 2.0 19 15 102.0 100.1
## 3 Toronto Raptors* 20 13 0.606 2.5 20 13 99.8 96.4
## 4 Chicago Bulls 18 12 0.600 3.0 16 14 101.1 100.0
## 5 Orlando Magic 19 13 0.594 3.0 19 13 101.0 98.4
## 6 Miami Heat* 18 13 0.581 3.5 17 14 97.0 95.5
## 7 Boston Celtics* 18 14 0.563 4.0 20 12 103.1 99.1
## 8 Indiana Pacers* 18 14 0.563 4.0 20 12 102.7 99.1
## 9 Detroit Pistons* 18 15 0.545 4.5 18 15 101.4 99.9
## 10 Charlotte Hornets* 17 14 0.548 4.5 18 13 102.5 99.7
## 11 New York Knicks 15 18 0.455 7.5 15 18 98.0 99.5
## 12 Washington Wizards 14 16 0.467 7.0 12 18 101.5 104.4
## 13 Milwaukee Bucks 13 21 0.382 10.0 10 24 97.8 103.6
## 14 Brooklyn Nets 9 23 0.281 13.0 9 23 97.1 103.4
## 15 Philadelphia 76ers 3 31 0.088 20.0 5 29 92.5 104.4
##
## $West
## western_conference w l w_lpercent gb pw pl ps_g pa_g
## 1 Golden State Warriors* 30 2 0.938 — 26 6 114.1 102.0
## 2 San Antonio Spurs* 28 6 0.824 3.0 30 4 102.0 88.6
## 3 Oklahoma City Thunder* 23 10 0.697 7.5 25 8 108.7 100.5
## 4 Los Angeles Clippers* 21 13 0.618 10.0 20 14 102.9 100.6
## 5 Dallas Mavericks* 19 13 0.594 11.0 18 14 102.3 100.8
## 6 Memphis Grizzlies* 18 16 0.529 13.0 13 21 96.4 99.4
## 7 Houston Rockets* 16 18 0.471 15.0 15 19 104.2 105.8
## 8 Utah Jazz 14 17 0.452 15.5 15 16 97.0 97.3
## 9 Portland Trail Blazers* 14 21 0.400 17.5 16 19 101.2 102.2
## 10 Sacramento Kings 12 20 0.375 18.0 13 19 104.2 107.3
## 11 Denver Nuggets 12 21 0.364 18.5 11 22 98.9 103.8
## 12 Minnesota Timberwolves 12 21 0.364 18.5 13 20 100.1 103.0
## 13 Phoenix Suns 12 23 0.343 19.5 14 21 102.8 105.6
## 14 New Orleans Pelicans 10 22 0.313 20.0 11 21 101.7 106.6
## 15 Los Angeles Lakers 6 27 0.182 24.5 6 27 96.8 107.2
## # A tibble: 664 x 31
## rk player pos age tm g gs mp fg fga fgpercent
## <dbl> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 Álex … SG 24 OKC 75 8 15.1 1.5 3.9 0.395
## 2 2 Quinc… PF 27 BRK 70 8 19.4 1.9 5.2 0.356
## 3 3 Steve… C 24 OKC 76 76 32.7 5.9 9.4 0.629
## 4 4 Bam A… C 20 MIA 69 19 19.8 2.5 4.9 0.512
## 5 5 Arron… SG 32 ORL 53 3 12.9 1.2 3.1 0.401
## 6 6 Cole … C 29 MIN 21 0 2.3 0.2 0.7 0.333
## 7 7 LaMar… C 32 SAS 75 75 33.5 9.2 18 0.51
## 8 8 Jarre… C 19 BRK 72 31 20 3.3 5.5 0.589
## 9 9 Kadee… PG 25 BOS 18 1 5.9 0.3 1.2 0.273
## 10 10 Tony … SF 36 NOP 22 0 12.4 2 4.1 0.484
## # … with 654 more rows, and 20 more variables: x3p <dbl>, x3pa <dbl>,
## # x3ppercent <dbl>, x2p <dbl>, x2pa <dbl>, x2ppercent <dbl>,
## # efgpercent <dbl>, ft <dbl>, fta <dbl>, ftpercent <dbl>, orb <dbl>,
## # drb <dbl>, trb <dbl>, ast <dbl>, stl <dbl>, blk <dbl>, tov <dbl>,
## # pf <dbl>, pts <dbl>, link <chr>
players %>%
dplyr::filter(mp > 20, pos %in% c("SF")) %>%
dplyr::select(player, link) %>%
dplyr::distinct()
## # A tibble: 51 x 2
## player link
## <chr> <chr>
## 1 Justin Anderson /players/a/anderju01.html
## 2 Giannis Antetokounmpo /players/a/antetgi01.html
## 3 Carmelo Anthony /players/a/anthoca01.html
## 4 Trevor Ariza /players/a/arizatr01.html
## 5 Matt Barnes /players/b/barnema02.html
## 6 Kent Bazemore /players/b/bazemke01.html
## 7 Bojan Bogdanović /players/b/bogdabo02.html
## 8 Jimmy Butler /players/b/butleji01.html
## 9 DeMarre Carroll /players/c/carrode01.html
## 10 Vince Carter /players/c/cartevi01.html
## # … with 41 more rows
## # A tibble: 595 x 30
## rk player pos age tm g gs mp fg fga fgpercent
## <dbl> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 Álex … SG 23 OKC 68 6 1055 4.6 11.6 0.393
## 2 2 Quinc… PF 26 TOT 38 1 558 4.5 11 0.412
## 3 2 Quinc… PF 26 DAL 6 0 48 3.7 12.7 0.294
## 4 2 Quinc… PF 26 BRK 32 1 510 4.6 10.8 0.425
## 5 3 Steve… C 23 OKC 80 80 2389 5.6 9.9 0.571
## 6 4 Arron… SG 31 SAC 61 45 1580 4.2 9.6 0.44
## 7 5 Alexi… C 28 NOP 39 15 584 5.5 11 0.5
## 8 6 Cole … C 28 MIN 62 0 531 3.1 5.8 0.523
## 9 7 LaMar… PF 31 SAS 72 72 2335 7.7 16.2 0.477
## 10 8 Lavoy… PF 27 IND 61 5 871 3.2 6.9 0.458
## # … with 585 more rows, and 19 more variables: x3p <dbl>, x3pa <dbl>,
## # x3ppercent <dbl>, x2p <dbl>, x2pa <dbl>, x2ppercent <dbl>, ft <dbl>,
## # fta <dbl>, ftpercent <dbl>, orb <dbl>, drb <dbl>, trb <dbl>,
## # ast <dbl>, stl <dbl>, blk <dbl>, tov <dbl>, pf <dbl>, pts <dbl>,
## # link <chr>
players <- NBAPerGameStatisticsPer36Min(season = 2019) %>%
dplyr::filter(pos %in% c("SF", "PF")) %>%
dplyr::top_n(n = 10, pts) %>%
dplyr::select(player, link) %>%
dplyr::distinct()
## # A tibble: 10 x 2
## player link
## <chr> <chr>
## 1 Giannis Antetokounmpo /players/a/antetgi01.html
## 2 Kevin Durant /players/d/duranke01.html
## 3 Paul George /players/g/georgpa01.html
## 4 Blake Griffin /players/g/griffbl01.html
## 5 LeBron James /players/j/jamesle01.html
## 6 Kawhi Leonard /players/l/leonaka01.html
## 7 Zhou Qi /players/q/qizh01.html
## 8 Julius Randle /players/r/randlju01.html
## 9 Alan Williams /players/w/willial03.html
## 10 Christian Wood /players/w/woodch01.html
Query each player in the list
player_stats <- NBAPlayerPerGameStats(players[1, 2]) %>%
dplyr::filter(!is.na(age)) %>%
dplyr::mutate(player = as.character(players[1, 1]))
Append the stats from each player into a df
for(i in 2:dim(players)[1]){
tmp <- NBAPlayerPerGameStats(players[i, 2]) %>%
dplyr::filter(!is.na(age)) %>%
dplyr::mutate(player = as.character(players[i, 1]))
player_stats <- dplyr::bind_rows(player_stats, tmp)
}
Plot everything
p <- ggplot2::ggplot(data = player_stats,
aes(x = age, y = efgpercent, group = player))
p + ggplot2::geom_line(alpha = .25) +
ggplot2::geom_point(alpha = .25) +
ggplot2::scale_y_continuous("effective field goal %age", limit = c(0, 1),
labels = percent) +
ggplot2::geom_line(data = dplyr::filter(player_stats, player == "Anthony Davis"),
aes(x = age, y = efgpercent), size = 1, col = "#1f78b4") +
ggplot2::geom_point(data = dplyr::filter(player_stats, player == "Anthony Davis"),
aes(x = age, y = efgpercent), size = 1, col = "#1f78b4") +
ggplot2::geom_line(data = dplyr::filter(player_stats, player == "DeMarcus Cousins"),
aes(x = age, y = efgpercent), size = 1, col = "#33a02c") +
ggplot2::geom_point(data = dplyr::filter(player_stats, player == "DeMarcus Cousins"),
aes(x = age, y = efgpercent), size = 1, col = "#33a02c") +
ggplot2::theme_bw()
## rk player pos age tm g gs mp fg fga fgpercent x3p x3pa
## 1 1 Álex Abrines SG 24 OKC 75 8 1134 5.0 12.7 0.395 3.7 9.7
## 2 2 Quincy Acy PF 27 BRK 70 8 1359 4.6 13.0 0.356 3.6 10.4
## 3 3 Steven Adams C 24 OKC 76 76 2487 8.9 14.2 0.629 0.0 0.0
## 4 4 Bam Adebayo C 20 MIA 69 19 1368 6.4 12.5 0.512 0.0 0.3
## 5 5 Arron Afflalo SG 32 ORL 53 3 682 4.7 11.6 0.401 1.9 5.0
## 6 6 Cole Aldrich C 29 MIN 21 0 49 5.1 15.3 0.333 0.0 0.0
## x3ppercent x2p x2pa x2ppercent ft fta ftpercent orb drb trb ast stl
## 1 0.380 1.4 3.1 0.443 1.7 2.0 0.848 1.1 3.9 5.0 1.2 1.7
## 2 0.349 1.0 2.6 0.384 1.8 2.1 0.817 1.4 7.8 9.2 2.0 1.2
## 3 0.000 8.9 14.2 0.631 3.2 5.7 0.559 7.7 6.0 13.7 1.8 1.8
## 4 0.000 6.4 12.2 0.523 4.7 6.6 0.721 4.3 9.7 14.0 3.7 1.2
## 5 0.386 2.7 6.6 0.413 1.6 1.9 0.846 0.3 4.5 4.7 2.2 0.3
## 6 NA 5.1 15.3 0.333 2.0 6.1 0.333 3.1 12.2 15.3 3.1 2.0
## blk tov pf pts x ortg drtg link
## 1 0.4 1.1 5.4 15.4 NA 116 110 /players/a/abrinal01.html
## 2 1.0 2.1 5.3 14.7 NA 99 110 /players/a/acyqu01.html
## 3 1.6 2.6 4.3 21.1 NA 125 107 /players/a/adamsst01.html
## 4 1.5 2.4 5.1 17.5 NA 116 105 /players/a/adebaba01.html
## 5 0.6 1.5 4.0 12.8 NA 98 115 /players/a/afflaar01.html
## 6 1.0 1.0 11.2 12.2 NA 85 107 /players/a/aldrico01.html
## rk player pos age tm g mp per tspercent x3par ftr
## 1 1 Álex Abrines SG 24 OKC 75 1134 9.0 0.567 0.759 0.158
## 2 2 Quincy Acy PF 27 BRK 70 1359 8.2 0.525 0.800 0.164
## 3 3 Steven Adams C 24 OKC 76 2487 20.6 0.630 0.003 0.402
## 4 4 Bam Adebayo C 20 MIA 69 1368 15.7 0.570 0.021 0.526
## 5 5 Arron Afflalo SG 32 ORL 53 682 5.8 0.516 0.432 0.160
## 6 6 Cole Aldrich C 29 MIN 21 49 6.0 0.340 0.000 0.400
## orbpercent drbpercent trbpercent astpercent stlpercent blkpercent
## 1 2.5 8.9 5.6 3.4 1.7 0.6
## 2 3.1 17.1 10.0 6.0 1.2 1.6
## 3 16.6 13.9 15.3 5.5 1.8 2.8
## 4 9.7 21.6 15.6 11.0 1.2 2.5
## 5 0.6 10.1 5.3 6.2 0.3 1.1
## 6 7.0 28.6 17.6 8.2 2.0 1.8
## tovpercent usgpercent x ows dws ws ws_48 x_2 obpm dbpm bpm vorp
## 1 7.4 12.7 NA 1.3 1.0 2.2 0.094 NA -0.5 -1.7 -2.2 -0.1
## 2 13.3 14.4 NA -0.1 1.1 1.0 0.036 NA -2.0 -0.2 -2.2 -0.1
## 3 13.3 16.7 NA 6.7 3.0 9.7 0.187 NA 2.2 1.1 3.3 3.3
## 4 13.6 15.9 NA 2.3 1.9 4.2 0.148 NA -1.6 1.8 0.2 0.8
## 5 10.8 12.5 NA -0.1 0.2 0.1 0.009 NA -4.1 -1.8 -5.8 -0.7
## 6 5.4 16.8 NA -0.1 0.1 0.0 -0.013 NA -7.0 0.0 -7.0 -0.1
## link
## 1 /players/a/abrinal01.html
## 2 /players/a/acyqu01.html
## 3 /players/a/adamsst01.html
## 4 /players/a/adebaba01.html
## 5 /players/a/afflaar01.html
## 6 /players/a/aldrico01.html
Look at selector gadget for a team’s website, e.g. Denver Nuggets. Suppose you want to find everybody who played for the Nuggets last year, and then their stats. Remember to use Chrome (ugh).
## Loading required package: xml2
url <- "http://www.basketball-reference.com/teams/DEN/2017.html"
links <- xml2::read_html(url) %>%
rvest::html_nodes(".center+ .left a") %>%
rvest::html_attr('href')
## [1] "/players/a/arthuda01.html" "/players/b/bartowi01.html"
## [3] "/players/b/beaslma01.html" "/players/c/chandwi01.html"
## [5] "/players/f/farieke01.html" "/players/g/gallida01.html"
## [7] "/players/g/geeal01.html" "/players/h/harriga01.html"
## [9] "/players/h/hernaju01.html" "/players/h/hibbero01.html"
## [11] "/players/j/jokicni01.html" "/players/m/millemi01.html"
## [13] "/players/m/mudiaem01.html" "/players/m/murraja01.html"
## [15] "/players/n/nelsoja01.html" "/players/n/nurkiju01.html"
## [17] "/players/o/obryajo01.html" "/players/p/plumlma01.html"
## [19] "/players/s/stokeja01.html"