Published
Edited
Jan 29, 2022
Teacher Salary Between 2016 and 2020
Number of Middle Age Himalayan Climbers Is Increasing Over Time
Insert cell
Insert cell
Insert cell
Insert cell
overlap = 7
Insert cell
height = 1292
//data.series.length * 17
Insert cell
margin = ({top: 120, right: 40, bottom: 50, left: 100})
Insert cell
x = d3.scaleLinear()
.domain(d3.extent(data.age))
.range([margin.left, width - margin.right])
Insert cell
y = d3.scalePoint()
.domain(data.series.map(d => d.name))
.range([margin.top,height - margin.bottom])
Insert cell
z = d3.scaleLinear()
.domain([0, d3.max(data.series, d => d3.max(d.values))]).nice()
// define distance between bars
.range([0,-overlap * y.step()])
Insert cell
width
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom + 10})`)
.call(d3.axisBottom(x)
.ticks(width / 80)
.tickPadding(10)
.tickSizeOuter(0)
.tickSizeInner(10))
// .call(g => g.select(".domain").remove())
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).tickSize(0).tickPadding(10))
.call(g => g.select(".domain").remove())

Insert cell
area = d3.area()
.curve(d3.curveBasis)
.defined(d => !isNaN(d))
.x((d, i) => x(data.age[i]))
.y0(0)
.y1(d => z(d))
Insert cell
line = area.lineY1()
Insert cell
color = d3.scaleSequential(d3.interpolate('#6D83F2','white'))
// a7a29f
Insert cell
data2 = d3.csvParse(await FileAttachment("data@4.csv").text(), d3.autoType)
Insert cell
data.series.reverse()
Insert cell
data = {
const data = d3.csvParse(await FileAttachment("data@4.csv").text(), d3.autoType);
const age = Array.from(d3.group(data, d => +d.age).keys()).sort(d3.ascending)
return {
age: age,
series: d3.groups(data, d => d.year).map(([name, values]) => {
const value = new Map(values.map(d => [+d.age, d.n]));
return {name, values: age.map(d => value.get(d))};
})
}
}
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