Published
Edited
Feb 15, 2021
1 fork
Importers
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
FileAttachment("lifetime_wealth.csv")
Insert cell
data = {
const text = await FileAttachment("lifetime_wealth.csv").text();
// const parseDate = d3.utcParse("%Y");
return d3.csvParse(text, ({year, race, type, wealth_lifetime}) => ({
// year: parseDate(year),
year: +year,
race: race,
type: type,
wealth: +wealth_lifetime
}));
}
Insert cell
Insert cell
group_data = Array.from(d3.group(data, d => d.race))
Insert cell
color_key = Array.from(d3.group(data, d => d.race).keys())
Insert cell
year_range = Array.from(d3.group(data, d => d.year).keys())
Insert cell
Insert cell
Insert cell
width = 900
Insert cell
Insert cell
Insert cell
x = d3.scaleBand()
.domain(year_range)
.range([margin.left, width - margin.right])
.paddingInner(0.04)
Insert cell
y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.wealth)])
.range([height, 0])
Insert cell
color = d3.scaleOrdinal()
.domain(color_key)
.range(["#eb5e0b", "#5eaaa8"])
// .range(["red", "yellow"])

Insert cell
Insert cell
xAxis = d3.axisBottom(x)
.tickPadding(5)

Insert cell
yAxis = d3.axisLeft(y)
.tickPadding(5)
Insert cell
line = d3.line()
.x(d => x(d.year))
.y(d => y(d.wealth))
.curve(d3.curveCardinal.tension(.001))
Insert cell
Insert cell
Insert cell
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