Skip to content

This project focuses on LBJ's career stats, including how he played on different teams and how the first five years of his career compare to today

Notifications You must be signed in to change notification settings

Shu-Ann/NBA-LeBron-James-stats-R-Shiny

Repository files navigation

NBA-LeBron-James-stats-R-Shiny

This project focuses on LBJ's career stats, including overall stats, shooting stats and the data when he against others, also the comparsion about how he played on different teams and ages.

Data Source: A. LeBron James’s total stats in regular session and playoff games from 2003 to 2021 https://www.basketball-reference.com/players/j/jamesle01/gamelog/2021

B. LeBron James’s shooting distance in regular session and playoff games from 2003 to 2021 https://www.nba.com/stats/events/?flag=3&CFID=33&CFPARAMS=2020-21&PlayerID=2544&ContextMeasure=FGA&Season=2020-21&section=player&sct=plot

Introduction and Motivation

I have been an NBA fan when I was a kid. There are over 400 players in NBA, and in every single year, some of them could be eliminated. In a such competitive league, LeBron James not only still survive, but also one of the legends in NBA. Although he is 37 years old, he is still among the top performers in the league. As a result, I am interested with his career data and would like to verify that if LeBron James’s stats are not affected by his physical age and other factors.

There is a lot of analytical data can be found on the Internet; however, most of them are season by season and lack an overall integrated analysis. Hence, I would like to know more about his career integrated data changes. From NBA fans side, we could expect how his games may look like and how his style of playing ball could change in the future.

Data Wrangling

Step 1: Obtain data and save into .csv files

Dataset: 截圖 2022-05-13 下午3 58 25

Step 2: Combine files

each season’s data have to combine together by using R libraries, readr and data.table, and for loop

Step 3: Transform into a data frame

Transform the data from a csv file into a dataframe to have better view and easier to clean the data by using R library tidyverse.

Step 4: Clean data

There are some “Inactive”, “Did Not Dress” or “Did Not Play” records in data which need to be deleted.

截圖 2022-05-13 下午3 59 04

Data Checking

Check the dataset by using Tableau

截圖 2022-05-13 下午4 04 01

截圖 2022-05-13 下午4 05 09

Data Exploration

By R:

The graph tells the stats in first five year and recent five year.

截圖 2022-05-13 下午4 06 22

Displays the situation in different teams.

截圖 2022-05-13 下午4 07 16

By Tableau:

3 point shooting attempts VS Field goal (2 points) shooting attempts trend

截圖 2022-05-13 下午4 08 26

The data of shooting, separating by first five years and recent five year in two colors which can tell that how the shooting area change. 截圖 2022-05-13 下午4 09 45

More Exploartions check out in Project file!

Data Visualization

The visualization part is done by R Shiny. The data I used is from 2003 to 2022, which is from his first career year till now. The completed R script can be found in DVP.R file. The needed data are dvpallgame.csv, shot_accuracy.csv, dvpshooting.csv and winrate.csv.

On the first page- Overall Stats

This page shows the overall trend from the first career year to 2022. There are four interactive plots. 2/3 point shooting stats and rebound/block stats.

截圖 2022-06-17 下午6 44 26

plot-

截圖 2022-06-17 下午6 51 59

On the top left is shooting attempt trend, we focus on 2 point and 3 point shot. As we all know, when people impacted by aging, they usually change their playing style from the shot closed to basket to 3 point shot in order to avoid body collision and protect themselves.

On the top right is rebound/block trend. Again, when player influenced by aging, their physical status may not be as good as when they were young, and the relative rebounds and blocks will decline, because the body can no longer withstand too many bounces and collisions.

截圖 2022-06-17 下午6 54 56

When mouse hovering, the stats of corresponding age will be highlight.

Second page- Shooting.

The second page focus on the shooting stats.

From the top to bottom, the plots would like to display- shooting accuracy at different zones, shooting frequency, total number of shooting attempt and the shooting type proportion.

截圖 2022-06-17 下午7 04 40

截圖 2022-06-17 下午7 04 56

The users first can choose whether they want to compare the stats by different teams or age.

While team- there are four selections

截圖 2022-06-17 下午7 07 31

While age- the drop down menu change the team options to age from 18 to 37 years old.

截圖 2022-06-17 下午7 08 10

For example, users can choose 18 vs 28 to compare and check out the data at the sepecfic age.

截圖 2022-06-17 下午7 09 29

Third page- Win Rate

The final page is abot the win rate when against other teams. There are two plot on this page, one is map and the other is a bar chart.

截圖 2022-06-17 下午7 10 54

Again, users can choose whether they would like to know more about in different teams or ages- 截圖 2022-06-17 下午7 12 17

When click on the logo on the map, it shows the detail data including win rate, points, field goals, 3 points, rebounds and blocks on average of all period (team or age). 截圖 2022-06-17 下午7 13 42

Below is a bar chart, when mouse hover, the selected bar would be highlight. 截圖 2022-06-17 下午7 15 54

Next Step

This project done by R Shiny. Shiny is one of the tools that allow users to build a webpage visualzation with interactive functions; however, customized design is not easy to implement by Shiny. As a result, the next step I am tring to do is to implement the visualization part by D3 which is one of the packages that in javascript.

Now, try on DVP.R and have fun!

About

This project focuses on LBJ's career stats, including how he played on different teams and how the first five years of his career compare to today

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages