Public
Edited
Mar 11, 2024
2 stars
Insert cell
Insert cell
Insert cell
selection // brush an axis below to see this update!
Insert cell
Insert cell
data = {
const col0 = rawData.columns[0];
const result = rawData.map((d) => ({
[col0]: d[col0]
}));

for (const column of rawData.columns.slice(1)) {
const xScale = x.get(column);
const vals = rawData
.map((d, i) => ({ x: d[column], index: i }))
.filter((d) => d.x != null);
const placedPoints = useSpacedJitter
? spacedJitter(vals, (d) => xScale(d.x), [0, 40], {
edgeSpacing: 0.5
})
: vals.map((d) => ({ x: xScale(d.x), y: Math.random() * 40, datum: d }));
for (const { x, y, datum } of placedPoints) {
result[datum.index][column] = { x, y, rawX: datum.x };
}
}

result.columns = rawData.columns;
return result;
}
Insert cell
// Create an horizontal (*x*) scale for each key.
x = new Map(
Array.from(keys, (key) => [
key,
d3.scaleLinear(
d3.extent(rawData, (d) => d[key]),
[marginLeft, width - marginRight]
)
])
)
Insert cell
// Create the vertical (*y*) scale.
y = d3.scalePoint(keys, [marginTop, height - marginBottom])
Insert cell
width = 928
Insert cell
height = keys.length * 100
Insert cell
marginTop = 120
Insert cell
marginRight = 10
Insert cell
marginLeft = 10
Insert cell
marginBottom = 20
Insert cell
rawData = FileAttachment("cars.csv").csv({ typed: true })
Insert cell
keys = rawData.columns.slice(1)
Insert cell
import {legend as Legend} from "@d3/color-legend"
Insert cell
import { spacedJitter } from "@jtrim-ons/avoiding-overlaps-in-jitter-plots";
Insert cell
columnOrientedData = (await FileAttachment("column-oriented-data.json").json())
.combinedDataObjectColumnOriented
Insert cell
ltlas = new Set(config.areasGeogLevelObject.lower)
Insert cell
config = FileAttachment("config.json").json()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more