I’m a bit stuck on how to create a stacked area chart – the part I’m stuck on is how to properly use the d3.stack( ) function. I’ve trying scouring guides and Mike’s examples but am still spinning in my wheels.

Essentially, what I have is an array with 1000 rows and 3 columns:

where each column represents a “category”. Since I’m modeling the SIR for epidemiology, column 1 would be the ‘susceptible’ group, column 2 would be the ‘infected group’, and column 3 would be the ‘recovered’ group.

Here’s my notebook: SIR Model Stacked Area / William Pang / Observable

(which builds on the work I’ve done here: SIR Model / William Pang / Observable)

Most of the examples out there seem to use the key function with already defined categorial names, but mine is just an array of results that are generated by computing the numerical solution for a bunch of equations.

My goal is to create a graph where there is a zero baseline and the values for each point add up so the topline is always 1 (e.g. Susceptible + Infected + Recovered = 0.989 + 0.011 + 0 = 1)

Any help would be appreciated! The goal is to create a stacked area graph similar to what 3blue1brown has done (Simulating an epidemic - YouTube)