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 38 6 0.864 — 36 8 119.5 106.9
## 2 Miami Heat 29 12 0.690 7.5 26 16 109.0 105.2
## 3 Toronto Raptors 28 14 0.667 9.0 29 13 111.8 105.9
## 4 Philadelphia 76ers 28 16 0.636 10.0 27 17 108.5 104.9
## 5 Boston Celtics 27 14 0.659 9.5 28 13 111.7 105.6
## 6 Indiana Pacers 27 15 0.628 10.0 26 17 106.9 103.8
## 7 Orlando Magic 20 23 0.465 17.5 20 23 103.7 104.4
## 8 Brooklyn Nets 18 23 0.439 18.5 18 23 109.2 111.5
## 9 Detroit Pistons 16 27 0.372 21.5 19 24 109.1 110.9
## 10 Chicago Bulls 16 28 0.364 22.0 19 25 105.8 107.8
## 11 Charlotte Hornets 15 29 0.341 23.0 13 31 103.8 110.6
## 12 Washington Wizards 13 28 0.317 23.5 14 27 114.5 120.2
## 13 Cleveland Cavaliers 12 31 0.279 25.5 10 33 105.2 114.1
## 14 New York Knicks 11 32 0.256 26.5 11 32 104.2 112.8
## 15 Atlanta Hawks 10 33 0.233 27.5 10 33 107.6 117.4
##
## $West
## western_conference w l w_lpercent gb pw pl ps_g pa_g
## 1 Los Angeles Lakers 34 8 0.810 — 31 11 114.2 105.6
## 2 Los Angeles Clippers 30 13 0.698 4.5 30 13 116.2 109.6
## 3 Denver Nuggets 29 12 0.690 4.5 26 16 106.9 103.0
## 4 Utah Jazz 29 13 0.690 5.0 26 16 110.5 106.4
## 5 Dallas Mavericks 27 15 0.643 7.0 30 12 116.7 109.4
## 6 Houston Rockets 26 15 0.634 7.5 26 15 118.6 114.2
## 7 Oklahoma City Thunder 24 19 0.558 10.5 24 19 109.6 108.0
## 8 Memphis Grizzlies 20 22 0.476 14.0 18 24 113.5 115.8
## 9 Phoenix Suns 18 24 0.429 16.0 20 22 113.5 114.0
## 10 Portland Trail Blazers 18 26 0.409 17.0 19 25 111.5 113.9
## 11 San Antonio Spurs 17 23 0.415 16.0 19 22 111.0 112.1
## 12 New Orleans Pelicans 16 27 0.372 18.5 17 26 114.2 117.7
## 13 Minnesota Timberwolves 15 27 0.357 19.0 17 25 111.4 114.7
## 14 Sacramento Kings 15 27 0.357 19.0 17 25 106.6 109.9
## 15 Golden State Warriors 10 34 0.227 25.0 12 32 105.2 113.2
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 and append the stats from each player into a df.
for(i in 1:dim(players)[1]){
print(i)# i <- 7
try({
tmp <- NBAPlayerPerGameStats(players[i, 2]) %>%
dplyr::filter(!is.na(age)) %>%
dplyr::mutate(player = as.character(players[i, 1]))
if(is.numeric(tmp$g)){
if(exists("player_stats")){
player_stats <- rbind(player_stats, tmp)
} else{
player_stats <- tmp
}
}
}, silent = T)
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
Plot everything
p <- ggplot2::ggplot(data = player_stats,
aes(x = age, y = efgpercent, group = player, col = 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::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"