shots_player = FileAttachment("data/shots_player.csv").csv({typed: true})
player_images = FileAttachment("data/player_images.csv").csv({typed: true})
player_list = [...new Set(shots_player.map(i => i.namePlayer))].sort()
NBA Shot Charts
Observable
interactive
Analysis of NBA player shooting stats for 2022-23 regular season. Interactive shot charts created with Observable Plot.
Background
I’m always in awe of the visual content I see in the sports analytics world. This week, I wanted explore NBA stat data and give something new a shot. Wrangled data from nbastatR
to get the latest 2022-23 season stats for players and their shot locations. Initially, I tried out this graphic with ggplot2
and an easy to use library, BasketballAnalyzer
, that has a built in function to generate the court lines.
After I posted my ggplot experiments on Twitter, a different conversation sparked - how could we do this in Observable? Of course Mike Bostock swooped in to the rescue. He had already assembled an impressive notebook visualizing LeBron James’ shots on the half court. I used his original notebook as a baseline to iterate on the graphics I created in R. Thankfully Mike did all the leg work with the court lines - I was dreading revisiting my notes from high school geometry!
Below is the result of my latest version. You can also find the notebook with the code here, pretty cool what you can do with Observable Plot!
Player Shot Chart
Settings