Public
Edited
Nov 3, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
table(ckdata, {})
Insert cell
out@3.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
black = d3.map(ckdata, d => d.black)
Insert cell
white = d3.map(ckdata, d => d.white)
Insert cell
asian = d3.map(ckdata, d => d.asian)
Insert cell
hispanic = d3.map(ckdata, d => d.hispanic)
Insert cell
yz = [white, black, asian, hispanic]
Insert cell
y01z = d3.stack()
.keys(d3.range(n))
(d3.transpose(yz)) // stacked yz
.map((data, i) => data.map(([y0, y1]) => [y0, y1, i]))
Insert cell
yMax = d3.max(yz, y => d3.max(y))
Insert cell
y1Max = d3.max(y01z, y => d3.max(y, d => d[1]))
Insert cell
y = d3.scaleLinear()
.domain([0, y1Max])
.range([height - margin.bottom, margin.top])
Insert cell
z = d3.scaleSequential(d3.interpolateBlues)
.domain([-0.5 * n, 1.5 * n])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
n = 4 // balck, white, asian, hispanic
Insert cell
height = 500
Insert cell
margin = ({top: 0, right: 0, bottom: 20, left: 0})
Insert cell
import {Legend} from "@d3/color-legend"
Insert cell
import { select } from "@jashkenas/inputs"
Insert cell
import { table } from "@john-guerra/tables"
Insert cell
import {swatches} from "@d3/color-legend"
Insert cell
d3 = require("d3@6")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more