NBAloveR is now updated!

Hello guys. It has been log time since the last time i have uploaded posts about NBAloveR... But finally the package is now updated! In this update, 5 functions added.

github.com

  • getHOF(): Function for getting list of Hall of Famers in NBA & WNBA history
  • getDraftResult(year): Function for getting draft results of each year
  • seasonSchedule(Team, year): Function for getting schedules and result of each game per season
  • statsCompare(player_list, Age): Function to compare selected players' PPG. Currently this is the only function which provides simple visualization.
  • getStandings(year, conf): Function for getting data of standings per season

mainly this updates provide easy accesses to online basketball data, however one of new functions provides simple visualizations this time.

So, let me show you some examples one by one!

Installation and loading package

devtools::install_github("koki25ando/NBAloveR")
library(NBAloveR)

getHOF(): Function for getting list of Hall of Famers in NBA & WNBA history

library(tidyverse)
nba_hof <- getHOF()
nba_hof %>% 
  ggplot(aes(x=Year)) + 
  geom_histogram(binwidth = 1)

f:id:kokiando:20181223194850j:plain
Distribution of number of Hall of Famers

nba_hof %>% 
  filter(Year == 2018)
Year Inductees Pos. Achievements
2018 Ray Allen G All-Time Leader three-point field goals (2,973)2× NBA champion (2008, 2013)10× NBA All-Star (2000–2002, 2004–2009, 2011)All-NBA Second Team (2005)All-NBA Third Team (2001)NBA Sportsmanship Award (2003)NBA Three-Point Shootout champion (2001)NBA All-Rookie Second Team (1997)Consensus first-team All-American (1996)UPI Player of the Year (1996)Big East Player of the Year (1996)2× First-team All-Big East (1995, 1996)USA Basketball Male Athlete of the Year (1995)Summer Olympics Gold: 2000
2018 Maurice Cheeks G NBA champion (1983)4× NBA All-Star (1983, 1986–1988)4× NBA All-Defensive First Team (1983–1986)NBA All-Defensive Second Team (1987)No. 10 retired by the Philadelphia 76ers
2018 Grant Hill F NBA All-Star (1995–1998, (2000–2001, 2005)All-NBA First Team (1997)4× All-NBA Second Team (1996, 1998–2000)NBA Co-Rookie of the Year (1995)NBA All-Rookie First Team (1995)3× NBA Sportsmanship Award (2005, 2008, 2010)2× NCAA champion (1991, 1992)Consensus first-team All-American (1994)Consensus second-team All-American (1993)ACC Player of the Year (1994)NABC Defensive Player of the Year (1993)Summer Olympics Gold: 1996No. 33 retired by Duke
2018 Jason Kidd G NBA champion (2011)10× NBA All-Star (1996, 1998, 2000–2004, 2007, 2008, 2010)5× All-NBA First Team (1999–2002, 2004)All-NBA Second Team (2003)4× NBA All-Defensive First Team (1999, 2001, 2002, 2006)5× NBA All-Defensive Second Team (2000, 2003–2005, 2007)NBA Co-Rookie of the Year (1995)5× NBA assists leader (1999–2001, 2003, 2004)2× NBA Sportsmanship Award (2012, 2013)USA Basketball Male Athlete of the Year (2007)No. 5 retired by the Brooklyn NetsConsensus first-team All-American (1994)USBWA National Freshman of the Year (1993)Pac-10 Player of the Year (1994)Pac-10 Freshman of the Year (1993)No. 5 retired by University of CaliforniaNaismith Prep Player of the Year (1992)2× California Mr. Basketball (1991, 1992)2× Summer Olympics Gold: 2000, 2008
2018 Steve Nash G NBA Most Valuable Player (2005, 2006)8× NBA All-Star (2002, 2003, 2005–2008, 2010, 2012)3× All-NBA First Team (2005–2007)2× All-NBA Second Team (2008, 2010)2× All-NBA Third Team (2002, 2003)5× NBA assists leader (2005–2007, 2010, 2011)4× 50–40–90 club (2006, 2008–2010)J. Walter Kennedy Citizenship Award (2007)Phoenix Suns Ring of HonorNo. 13 retired by Phoenix Suns2× FIBA AmeriCup MVP (1999, 2003)Lou Marsh Trophy (2005)3× Lionel Conacher Award (2002, 2005, 2006)2× WCC Player of the Year (1995, 1996)No. 11 retired by Santa Clara
2018 Katie Smith G-F WNBA champion (2006, 2008)WNBA Finals MVP (2008)2× All-WNBA First Team (2001, 2003)7× WNBA All-Star (2000–2003, 2005, 2006, 2009)WNBA scoring champion (2001)WNBA's All-Decade Team (2006)WNBA's Top 15 Players of All Time (2011)WNBA Top 20@20 (2016)Big Ten Player of the Year (1996)Chicago Tribune Silver Basketball (1996)3× Summer Olympics Gold: 2000, 2004, 20083× World Cup Gold: 1998, 2002 Bronze: 2006
2018 Tina Thompson F WNBA champion (1997, 1998, 1999, 2000)9× WNBA All-Star (1999–2003, 2006, 2007, 2009, 2013)WNBA All-Star Game MVP (2000)3× All-WNBA First Team (1997–1998, 2004)4× All-WNBA Second Team (1999–2002)WNBA's Top 15 Players of All Time (2011)WNBA Top 20@20 (2016)Member of WNBA All-Decade TeamRussian National League champion (2007)EuroLeague champion (2007)Romanian National League champion (2010)2× Summer Olympics Gold: 2004, 20082× World Cup Gold: 1998 Bronze: 2006
2018 Ora Mae Washington Women's Basketball Hall of Fame (2009)
2018 Dino Rađa F-C 2× EuroLeague champion (1989, 1990)FIBA European Selection (1991)FIBA Korać Cup champion (1992)3× Yugoslav League champion (1988–1990)2× Greek League champion (1998, 1999)Greek League Finals MVP (1998)2× Croatian League champion (2002, 2003)Yugoslav Cup winner (1990)Croatian Cup winner (2000)NBA All-Rookie Second Team (1994)EuroLeague Final Four MVP (1989)FIBA's 50 Greatest Players (1991)50 Greatest EuroLeague Contributors (2008)2× Summer Olympics Silver: 1988, 19922× FIBA World Cup Gold: 1990 Bronze: 19945x EuroBasket Gold: 1989, 1991 Bronze: 1987, 1993, 1995
2018 Charlie Scott G NBA champion (1976)3× NBA All-Star (1973–1975)2× ABA All-Star (1971, 1972)All-ABA First Team (1971)All-ABA Second Team (1972)ABA Rookie of the Year (1971)ABA All-Rookie First Team (1971)ABA All-Time Team2× Consensus second-team All-American (1969, 1970)ACC Athlete of the Year (1970)College Basketball Hall of Fame (2015)Summer Olympics Gold: 1968

getDraftResult(year): Function for getting draft results of each year

draft_from09_to2018 = list()
for (i in 1:10){
  base_year = 2008
  draft_from09_to2018[[i]] <- getDraftResult(year=base_year+i)
  draft_from09_to2018[[i]]$Year = paste0(base_year + i)
  print(draft_from09_to2018[[i]])
}

draft_result <- do.call(rbind, draft_from09_to2018)
names(draft_result)[1] <- "Rank"
draft_result$Team <- draft_result$Team %>% 
  str_remove("\\*")

library(treemap)
treemap(data.frame(table(draft_result$School)),
        index="Var1",
        vSize="Freq",
        type="index",
        title = "What college has the most NBA draft picks from 2009 to 2018?")

f:id:kokiando:20181223193035p:plain
What college has the most draft picks from 2009 to 2018?

seasonSchedule(Team, year): Function for getting schedules and result of each game per season

seasonSchedule(Team="GSW", year=2018)
    G              Date Start..ET. Var.4     Var.5 Var.6               Opponent Var.8 Var.9  Tm Opp  W  L Streak Notes
1   1 Tue, Oct 17, 2017     10:30p    NA Box Score              Houston Rockets     L       121 122  0  1    L 1      
2   2 Fri, Oct 20, 2017      9:30p    NA Box Score     @   New Orleans Pelicans     W       128 120  1  1    W 1      
3   3 Sat, Oct 21, 2017      8:00p    NA Box Score     @      Memphis Grizzlies     L       101 111  1  2    L 1      
4   4 Mon, Oct 23, 2017      8:30p    NA Box Score     @       Dallas Mavericks     W       133 103  2  2    W 1      
5   5 Wed, Oct 25, 2017     10:30p    NA Box Score              Toronto Raptors     W       117 112  3  2    W 2      
6   6 Fri, Oct 27, 2017     10:30p    NA Box Score           Washington Wizards     W       120 117  4  2    W 3      
7   7 Sun, Oct 29, 2017      8:30p    NA Box Score              Detroit Pistons     L       107 115  4  3    L 1      
8   8 Mon, Oct 30, 2017     10:30p    NA Box Score     @   Los Angeles Clippers     W       141 113  5  3    W 1      
9   9  Thu, Nov 2, 2017      8:00p    NA Box Score     @      San Antonio Spurs     W       112  92  6  3    W 2      
10 10  Sat, Nov 4, 2017      9:00p    NA Box Score     @         Denver Nuggets     W       127 108  7  3    W 3      
11 11  Mon, Nov 6, 2017     10:30p    NA Box Score                   Miami Heat     W        97  80  8  3    W 4      
12 12  Wed, Nov 8, 2017     10:30p    NA Box Score       Minnesota Timberwolves     W       125 101  9  3    W 5      
13 13 Sat, Nov 11, 2017      8:30p    NA Box Score           Philadelphia 76ers     W       135 114 10  3    W 6      
14 14 Mon, Nov 13, 2017     10:30p    NA Box Score                Orlando Magic     W       110 100 11  3    W 7      
15 15 Thu, Nov 16, 2017      8:00p    NA Box Score     @         Boston Celtics     L        88  92 11  4    L 1      
16 16 Sat, Nov 18, 2017      7:30p    NA Box Score     @     Philadelphia 76ers     W       124 116 12  4    W 1      
17 17 Sun, Nov 19, 2017      6:00p    NA Box Score     @          Brooklyn Nets     W       118 111 13  4    W 2      
18 18 Wed, Nov 22, 2017      8:00p    NA Box Score     @  Oklahoma City Thunder     L        91 108 13  5    L 1      
19 19 Fri, Nov 24, 2017     10:30p    NA Box Score                Chicago Bulls     W       143  94 14  5    W 1      
20 20 Sat, Nov 25, 2017      8:30p    NA Box Score         New Orleans Pelicans     W       110  95 15  5    W 2      
21  G              Date Start (ET)    NA                               Opponent              Tm Opp  W  L Streak Notes
22 21 Mon, Nov 27, 2017     10:30p    NA Box Score             Sacramento Kings     L       106 110 15  6    L 1      
23 22 Wed, Nov 29, 2017     10:30p    NA Box Score     @     Los Angeles Lakers     W    OT 127 123 16  6    W 1      
24 23  Fri, Dec 1, 2017      7:00p    NA Box Score     @          Orlando Magic     W       133 112 17  6    W 2      
25 24  Sun, Dec 3, 2017      7:00p    NA Box Score     @             Miami Heat     W       123  95 18  6    W 3      
26 25  Mon, Dec 4, 2017      8:00p    NA Box Score     @   New Orleans Pelicans     W       125 115 19  6    W 4      
27 26  Wed, Dec 6, 2017      8:00p    NA Box Score     @      Charlotte Hornets     W       101  87 20  6    W 5      
28 27  Fri, Dec 8, 2017      7:00p    NA Box Score     @        Detroit Pistons     W       102  98 21  6    W 6      
29 28 Mon, Dec 11, 2017     10:30p    NA Box Score       Portland Trail Blazers     W       111 104 22  6    W 7      
30 29 Thu, Dec 14, 2017     10:30p    NA Box Score             Dallas Mavericks     W       112  97 23  6    W 8      
31 30 Mon, Dec 18, 2017     10:30p    NA Box Score     @     Los Angeles Lakers     W    OT 116 114 24  6    W 9      
32 31 Wed, Dec 20, 2017     10:30p    NA Box Score            Memphis Grizzlies     W        97  84 25  6   W 10      
33 32 Fri, Dec 22, 2017     10:30p    NA Box Score           Los Angeles Lakers     W       113 106 26  6   W 11      
34 33 Sat, Dec 23, 2017      8:30p    NA Box Score               Denver Nuggets     L        81  96 26  7    L 1      
35 34 Mon, Dec 25, 2017      3:00p    NA Box Score          Cleveland Cavaliers     W        99  92 27  7    W 1      
36 35 Wed, Dec 27, 2017     10:30p    NA Box Score                    Utah Jazz     W       126 101 28  7    W 2      
37 36 Fri, Dec 29, 2017     10:30p    NA Box Score            Charlotte Hornets     L       100 111 28  8    L 1      
38 37 Sat, Dec 30, 2017      8:30p    NA Box Score            Memphis Grizzlies     W       141 128 29  8    W 1      
39 38  Wed, Jan 3, 2018      8:30p    NA Box Score     @       Dallas Mavericks     W       125 122 30  8    W 2      
40 39  Thu, Jan 4, 2018      8:00p    NA Box Score     @        Houston Rockets     W       124 114 31  8    W 3      
41 40  Sat, Jan 6, 2018      3:30p    NA Box Score     @   Los Angeles Clippers     W       121 105 32  8    W 4      
42  G              Date Start (ET)    NA                               Opponent              Tm Opp  W  L Streak Notes
43 41  Mon, Jan 8, 2018     10:30p    NA Box Score               Denver Nuggets     W       124 114 33  8    W 5      
44 42 Wed, Jan 10, 2018     10:30p    NA Box Score         Los Angeles Clippers     L       106 125 33  9    L 1      
45 43 Fri, Jan 12, 2018      8:00p    NA Box Score     @        Milwaukee Bucks     W       108  94 34  9    W 1      
46 44 Sat, Jan 13, 2018      7:30p    NA Box Score     @        Toronto Raptors     W       127 125 35  9    W 2      
47 45 Mon, Jan 15, 2018      8:00p    NA Box Score     @    Cleveland Cavaliers     W       118 108 36  9    W 3      
48 46 Wed, Jan 17, 2018      8:00p    NA Box Score     @          Chicago Bulls     W       119 112 37  9    W 4      
49 47 Sat, Jan 20, 2018      8:30p    NA Box Score     @        Houston Rockets     L       108 116 37 10    L 1      
50 48 Tue, Jan 23, 2018     10:30p    NA Box Score              New York Knicks     W       123 112 38 10    W 1      
51 49 Thu, Jan 25, 2018     10:30p    NA Box Score       Minnesota Timberwolves     W       126 113 39 10    W 2      
52 50 Sat, Jan 27, 2018      8:30p    NA Box Score               Boston Celtics     W       109 105 40 10    W 3      
53 51 Tue, Jan 30, 2018      9:00p    NA Box Score     @              Utah Jazz     L        99 129 40 11    L 1      
54 52  Fri, Feb 2, 2018     10:30p    NA Box Score     @       Sacramento Kings     W       119 104 41 11    W 1      
55 53  Sat, Feb 3, 2018      9:00p    NA Box Score     @         Denver Nuggets     L       108 115 41 12    L 1      
56 54  Tue, Feb 6, 2018     10:30p    NA Box Score        Oklahoma City Thunder     L       105 125 41 13    L 2      
57 55  Thu, Feb 8, 2018     10:30p    NA Box Score             Dallas Mavericks     W       121 103 42 13    W 1      
58 56 Sat, Feb 10, 2018      8:30p    NA Box Score            San Antonio Spurs     W       122 105 43 13    W 2      
59 57 Mon, Feb 12, 2018     10:30p    NA Box Score                 Phoenix Suns     W       129  83 44 13    W 3      
60 58 Wed, Feb 14, 2018     10:30p    NA Box Score     @ Portland Trail Blazers     L       117 123 44 14    L 1      
61 59 Thu, Feb 22, 2018     10:30p    NA Box Score         Los Angeles Clippers     W       134 127 45 14    W 1      
62 60 Sat, Feb 24, 2018      8:30p    NA Box Score        Oklahoma City Thunder     W       112  80 46 14    W 2      
63  G              Date Start (ET)    NA                               Opponent              Tm Opp  W  L Streak Notes
64 61 Mon, Feb 26, 2018      7:30p    NA Box Score     @        New York Knicks     W       125 111 47 14    W 3      
65 62 Wed, Feb 28, 2018      8:00p    NA Box Score     @     Washington Wizards     W       109 101 48 14    W 4      
66 63  Fri, Mar 2, 2018      7:30p    NA Box Score     @          Atlanta Hawks     W       114 109 49 14    W 5      
 [ reached getOption("max.print") -- omitted 20 rows ]

statsCompare(player_list, Age): Function to compare selected players' PPG. Currently this is the only function which provides simple visualization.

statsCompare(player_list =c("Kobe Bryant", "LeBron James", "Stephen Curry", 
                            "Kevin Durant", "Dirk Nowitzki", "Klay Thompson"), 
             Age=TRUE)

f:id:kokiando:20181223201618j:plain
Stats Comparison of Points per Game

getStandings(year, conf): Function for getting data of standings per season

getStandings(year=201, conf="ALL")
                     Team  W  L  W.L.   GB PW PL PS.G PA.G
1         Toronto Raptors 25 10 0.305    — 57 25 48.8 45.9
2         Milwaukee Bucks 22 10 0.268  1.5 61 21 45.6 42.3
3      Philadelphia 76ers 22 12 0.268  2.5 48 34 47.5 46.3
4   Golden State Warriors 22 11 0.268    — 53 29 46.5 44.5
5          Indiana Pacers 21 12 0.256    3 55 27 42.7 40.6
6   Oklahoma City Thunder 21 10 0.256    — 58 24 42.3 39.8
7          Denver Nuggets 21 10 0.256    — 56 26 41.6 39.4
8    Los Angeles Clippers 19 13 0.232  2.5 44 38 45.0 44.6
9      Los Angeles Lakers 19 13 0.232  2.5 46 36 44.2 43.5
10         Boston Celtics 18 13 0.220    5 57 25 42.0 39.6
11 Portland Trail Blazers 18 14 0.220  3.5 43 39 43.4 43.1
12      San Antonio Spurs 18 16 0.220  4.5 46 36 46.1 45.4
13        Houston Rockets 17 15 0.207  4.5 43 39 42.6 42.3
14       Sacramento Kings 17 15 0.207  4.5 37 45 44.8 45.4
15      Charlotte Hornets 16 15 0.195    7 48 34 42.8 41.8
16      Memphis Grizzlies 16 16 0.195  5.5 40 42 39.7 39.9
17              Utah Jazz 16 18 0.195  6.5 44 38 44.3 43.9
18        Detroit Pistons 15 15 0.183  7.5 38 44 39.8 40.2
19             Miami Heat 15 16 0.183    8 39 43 40.1 40.4
20          Brooklyn Nets 15 19 0.183  9.5 39 43 45.8 46.1
21       Dallas Mavericks 15 16 0.183    6 43 39 41.7 41.4
22   New Orleans Pelicans 15 18 0.183    7 44 38 46.8 46.4
23          Orlando Magic 14 17 0.171    9 30 52 38.9 40.4
24 Minnesota Timberwolves 14 18 0.171  7.5 39 43 43.2 43.6
25     Washington Wizards 13 20 0.159   11 30 52 45.9 47.7
26        New York Knicks  9 25 0.110 15.5 24 58 45.0 48.0
27          Atlanta Hawks  8 23 0.098   15 19 63 41.2 44.8
28          Chicago Bulls  8 25 0.098   16 17 65 40.5 44.5
29    Cleveland Cavaliers  8 25 0.098   16 20 62 41.5 44.9
30           Phoenix Suns  8 25 0.098   14 20 62 42.1 45.7

Conclusion

I hope this post help readers understand the package a little bit. And I really hope you guys this package useful. Without further ado, please try updated NBAloveR... and let me know what you think!

github.com

Also, if you are interested in this package, please refer to my last tutorial post.

kokiando.hatenablog.com

thanks,

Koki