Unovis: Super Bowl LIX's 26 drives as a Sankey, from where each started to how it ended, each team's flows in its colour
With JavaScript on, Unovis draws this figure here.
[
{
"from": "team:PHI",
"to": "band:Own 21-40",
"drives": 5,
"color": "#004c54"
},
{
"from": "band:Own 21-40",
"to": "result:Punt",
"drives": 2,
"color": "#004c54"
},
{
"from": "team:KC",
"to": "band:Own 1-20",
"drives": 4,
"color": "#e31837"
},
{
"from": "band:Own 1-20",
"to": "result:Punt",
"drives": 2,
"color": "#e31837"
},
{
"from": "band:Own 21-40",
"to": "result:Touchdown",
"drives": 1,
"color": "#004c54"
},
{
"from": "team:KC",
"to": "band:Own 21-40",
"drives": 8,
"color": "#e31837"
},
{
"from": "band:Own 21-40",
"to": "result:Punt",
"drives": 4,
"color": "#e31837"
},
{
"from": "team:PHI",
"to": "band:Own 1-20",
"drives": 2,
"color": "#004c54"
},
{
"from": "band:Own 1-20",
"to": "result:Interception",
"drives": 1,
"color": "#004c54"
},
{
"from": "team:PHI",
"to": "band:Own 41 to opp. 41",
"drives": 4,
"color": "#004c54"
},
{
"from": "band:Own 41 to opp. 41",
"to": "result:Field Goal",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 21-40",
"to": "result:Interception Touchdown",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Own 1-20",
"to": "result:Interception",
"drives": 1,
"color": "#e31837"
},
{
"from": "team:PHI",
"to": "band:Opp. 40 and in",
"drives": 2,
"color": "#004c54"
},
{
"from": "band:Opp. 40 and in",
"to": "result:Touchdown",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 21-40",
"to": "result:End of Half",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 1-20",
"to": "result:Field Goal",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 21-40",
"to": "result:Downs",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Own 41 to opp. 41",
"to": "result:Touchdown",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 1-20",
"to": "result:Touchdown",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Own 21-40",
"to": "result:Field Goal",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 21-40",
"to": "result:Fumble",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Opp. 40 and in",
"to": "result:Field Goal",
"drives": 1,
"color": "#004c54"
},
{
"from": "band:Own 21-40",
"to": "result:Touchdown",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Own 41 to opp. 41",
"to": "result:Downs",
"drives": 1,
"color": "#004c54"
},
{
"from": "team:KC",
"to": "band:Own 41 to opp. 41",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Own 41 to opp. 41",
"to": "result:Touchdown",
"drives": 1,
"color": "#e31837"
},
{
"from": "band:Own 41 to opp. 41",
"to": "result:End of Game",
"drives": 1,
"color": "#004c54"
}
]import { SUPER_BOWL_LIX_DRIVES } from "@sportsdataverse/examples/data";
import { loadLeague } from "@sportsdataverse/sdvplot";
import { teamColorScale } from "@sportsdataverse/sdvplot/unovis";
await loadLeague("nfl");
// where a drive started, in yards from the opponent's end zone
const band = (yardline: number) =>
yardline >= 80
? "Own 1-20"
: yardline >= 60
? "Own 21-40"
: yardline >= 41
? "Own 41 to opp. 41"
: "Opp. 40 and in";
// three columns: the team with the ball, where its drive started, how the drive ended (ESPN's words)
const counts = new Map<string, { source: string; target: string; team: string; value: number }>();
const add = (source: string, target: string, team: string) => {
const key = `${source}>${target}>${team}`;
const link = counts.get(key) ?? { source, target, team, value: 0 };
link.value += 1;
counts.set(key, link);
};
for (const d of SUPER_BOWL_LIX_DRIVES) {
add(`team:${d.team}`, `band:${band(d.yardline_100)}`, d.team);
add(`band:${band(d.yardline_100)}`, `result:${d.result}`, d.team);
}
const links = [...counts.values()];
const ids = [...new Set(links.flatMap((l) => [l.source, l.target]))];
const nodes = ids.map((id) => ({
id,
label: id.slice(id.indexOf(":") + 1),
team: id.startsWith("team:") ? id.slice(5) : undefined,
}));
// every flow in the colour of the team that had the ball; the band and result nodes stay grey
const color = teamColorScale("nfl", ["KC", "PHI"]);
// In the browser: new SingleContainer(el, { component: new Sankey(config()), height: 420 }, data())
export const browser = {
lib: "unovis",
component: "Sankey",
config: () => ({
label: (n: (typeof nodes)[number]) => n.label,
nodeColor: (n: (typeof nodes)[number]) => (n.team === undefined ? "#9ca3af" : color(n.team)),
linkColor: (l: (typeof links)[number]) => color(l.team),
nodeWidth: 14,
}),
data: () => ({ nodes: nodes.map((n) => ({ ...n })), links: links.map((l) => ({ ...l })) }),
width: 680,
height: 420,
label: `Super Bowl LIX's 26 drives, Kansas City's in red and Philadelphia's in green, flowing from the team to where the drive started and on to how it ended: ${links
.filter((l) => l.source.startsWith("band:"))
.map((l) => `${l.team} ${l.source.slice(5)} to ${l.target.slice(7)}, ${l.value}`)
.join("; ")}`,
} as const;
// Unovis draws only in a browser; without JavaScript the page shows each flow, its drives and its colour
links.map((l) => ({ from: l.source, to: l.target, drives: l.value, color: color(l.team) }));
Tags: unovis · sankey · teamColorScale · nfl. All sdvplot examples.