538 Theme Day

dataviz
chart-challenge
TIL
#30DayChartChallenge Day 30
Author
Published

April 30, 2024

Day 30

Here we are at the final day of the #30DayChartChallenge! Today’s theme is 538 and browsing through the archives, I found this fun prediction they made for the 2015 NBA draft class. 538’s predictions weren’t very far off but I felt that the table that presented the results could be spruced up a little.

I also saw this as a great opportunity to use great_tables, a Python package that makes it easy to make beautiful HTML tables. For certain types of messages, a table might be more effective than a chart and it’s really cool to be able to elevate tables into proper data visualisations too!

Code
import polars as pl
from great_tables import GT, md

# Data prep
draft = (pl.read_csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/nba-draft-2015/historical_projections.csv')
    .insert_column(index=0, column=pl.Series(name="Rank", values=range(1, 1091)))
    .filter(pl.col('Draft Year')==2015)
    .filter(pl.col('Rank')<=16)
    .drop(['ID','Draft Year'])
)


# Great Table
table = (
    GT(draft)
    .tab_header(
        title = md("# Top College Prospects for the 2015 NBA Draft"),
        subtitle= "Ranked by 538's projected Statistical Plus/Minus (SPM)"
    )
    .tab_spanner(
        label="Probability of becoming", 
        columns=['Projected SPM',
        'Superstar',
        'Starter',
        'Role Player',
        'Bust']
    )
    .tab_source_note(md(
        '<br><div style="text-align: left;">'
        "**#30DayChartChallenge** | Day 30 | 538" 
        "<br> **Source**: https://fivethirtyeight.com/features/projecting-the-top-50-players-in-the-2015-nba-draft-class/" 
        "<br> **Made by**: www.ddanieltan.com"
        "</div>"
        "<br>"
    ))
    .fmt_number(columns='Projected SPM', decimals=2, pattern='+{x}')
    .fmt_percent(columns=['Superstar','Starter','Role Player','Bust'])
    .data_color(columns="Superstar",palette=["lightblue", "darkgreen"]
    )
    .data_color(columns="Bust", palette=["lightyellow","pink",]
    )
    .fmt_nanoplot(columns="Projected SPM", plot_type="bar")
)

table

Top College Prospects for the 2015 NBA Draft

Ranked by 538's projected Statistical Plus/Minus (SPM)
Rank Player Position Probability of becoming
Projected SPM Superstar Starter Role Player Bust
1 Karl-Anthony Towns C
1.03
13.48% 42.72% 16.31% 27.50%
2 Justise Winslow SF
0.88
8.35% 51.09% 17.68% 22.88%
3 Stanley Johnson SF
0.68
6.78% 42.37% 27.85% 23.00%
4 Jahlil Okafor C
0.52
5.87% 40.99% 23.55% 29.59%
5 D`Angelo Russell PG
0.51
15.20% 34.23% 9.66% 40.91%
6 Dakari Johnson C
0.49
2.13% 36.75% 41.76% 19.35%
7 Devin Booker SG
0.47
7.34% 32.45% 39.02% 21.20%
8 Willie Cauley-Stein C
0.35
4.71% 40.60% 24.32% 30.37%
9 Rondae Hollis-Jefferson SF
0.31
1.46% 36.85% 39.25% 22.44%
10 Trey Lyles PF
0.27
2.24% 35.13% 40.31% 22.32%
11 Sam Dekker SF
0.25
0.87% 38.50% 32.91% 27.73%
12 Kelly Oubre Jr. SF
0.25
1.98% 37.90% 33.80% 26.32%
13 Tyus Jones PG
0.24
2.72% 41.46% 28.44% 27.38%
14 Kevon Looney PF
0.20
0.83% 35.56% 37.49% 26.12%
15 Myles Turner PF
0.076
2.94% 33.58% 31.85% 31.63%
16 Cliff Alexander PF
0.026
0.76% 29.48% 40.66% 29.10%

#30DayChartChallenge | Day 30 | 538
Source: https://fivethirtyeight.com/features/projecting-the-top-50-players-in-the-2015-nba-draft-class/
Made by: www.ddanieltan.com

TIL

  1. Polars has a very useful df.insert_column(index, column) that can specify the precise index to insert a new column at.

  2. Great Tables provides md() method that can allow one to style any text using common markdown, this includes HTML tags.

Reuse

Citation

BibTeX citation:
@online{tan2024,
  author = {Tan, Daniel},
  title = {538 {Theme} {Day}},
  date = {2024-04-30},
  url = {https://www.ddanieltan.com/posts/30-day-chart-30},
  langid = {en}
}
For attribution, please cite this work as:
Tan, Daniel. 2024. “538 Theme Day.” April 30, 2024. https://www.ddanieltan.com/posts/30-day-chart-30.