Simple Interactive Visualization of '16-17 NBA Stats With Shiny

Keenan Burke-Pitts
Posted on Jun 9, 2018

Purpose

Why I Chose This Project

Fantasy sports is a multi-billion-dollar industry. Most people play in leagues as an effective way to stay connected to friends, co-workers, and family through friendly competition. Most of us don't have enough time in our lives to stay current with all the updates and latest news about the sports we have interest in. To reconcile this challenge, I practiced my skills I developed in R to build a Shiny App that compiles in-depth stats on NBA players.

Questions to Answer

I set out to answer which players had the most values in multiple categories. I wanted to discover some of the mid-tier players in the ’16-’17 season that stood out in certain statistical categories to keep on my radar for next season.

Process

Where and How I Extracted the Data

To gather the data I needed, I first had to search the web and figure out what would would be the most efficient way to extract the stats. There are many websites that display NBA stats but most of them don’t make it simple to download to a .csv or .txt file. I discovered http://www.dougstats.com/16-17.html which had the relevant stats in a simple raw downloadable .txt file. The .txt files still needed a fair amount of data munging to tidy up for usage within the Shiny App.

I also extracted advanced stats from https://rotogrinders.com/pages/nba-advanced-player-stats-guards-181885 which included further statistics for the guard, forward, and center positions in the NBA. Since the advanced stats were in tables already, the most efficient way to extract the data was to use Pandas read_html method. Some of the tables extracted with Pandas were missing the column names so I used BeautifulSoup to extract them and combine them with the Pandas dataframe. I then exported it as a .csv file.

How I analyzed the data

Before I set up my Shiny App, I wanted to answer the following questions using dplyr:

#1. What is the correlation between minutes and primary stats?

Unsurprisingly there is a strong correlation between how many minutes are played and the primary statistics such as points, assists, rebounds, etc.

You can find the remainder of this answer in my GitHub repo.

#2. What is the mean and SD of primary stats. Per team? Per position?

You can find the remainder of this answer in my GitHub repo.

#3. Which players have the best PER's in the league per team? Per position? Per position on team?

#4. What is each team’s total PER?

#5. What are the central tendencies of primary stats? Per team? Per Position?

You can find the remainder of this answer in my GitHub repo.

#6. Who were the league leaders in primary stats?

#7. What was each team’s winning percentage?

#8.What is the correlation between team PER and team win ratio?

How I Visualized The Data

I created the app to display multiple data tables. A search for whatever keyword the user finds applicable (ie, player name, team name, position, stats category) is simple. The app also displays an interactive visualization of the correlation between team PER (player efficiency rating) and team winning percentage.

Results

Insights Gleaned

There didn't appear to be a clear correlation between team PER and team winning percentage.

A few players, when doing my analysis, appeared to offer solid value adds in later rounds of a draft; these players excelled at one or a few important categories but are generally overlooked because of their total minutes per game since they play behind more well-known star players.

The analysis helped me to narrow my focus on specific players so I can pay closer attention to what happens to their career next season. Sometimes a trade to a new team can increase a mid-tier players value if they have already shown promise playing behind another star player.

Improvement to be Made

This was a small-scale project that completed in the offseason. I only analyzed data from ’16-’17 season. Gleaning insights from the data of the previous season can be helpful, but many more intangible variables off the court or field are necessary to come to a confident decision about adding a player to my fantasy team. It is also helpful to glean insights quickly and efficiently while the season is taking place. I may figure out how to extract and import data in a more efficient process as a next step in the project.

You can view the project here: https://kiwibp.shinyapps.io/nbashiny/ and my code on GitHub here: https://github.com/Kiwibp/NYC-DSA-Bootcamp--R-Shiny-App. It was interesting to learn R and Shiny but I have currently have no intention to use them again in the short term. You can view other interactive data visualizations I've created with Tableau here: https://public.tableau.com/profile/keenan.burke.pitts.

 

About Author

Keenan Burke-Pitts

Keenan Burke-Pitts

Keenan has over 3 years of experience communicating and assisting in software and internet solutions to clients. Moving forward, Keenan plans to leverage his technical abilities, communication skills, and business understanding in the digital marketing world. Keenan graduated...
View all posts by Keenan Burke-Pitts >

Related Articles

Leave a Comment

Your email address will not be published. Required fields are marked *

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags