Published
Edited
Apr 8, 2021
1 fork
Insert cell
Insert cell
chart = {
const r = radius + padding / 2;
const beeswarmData =
new AccurateBeeswarm.AccurateBeeswarm(data, r, d => x(d.value))
.oneSided()
.calculateYPositions()
.map(({datum, x, y}) => ({data: datum, x, y}));
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

svg.append("g")
.call(xAxis);

svg.append("g")
.selectAll("circle")
.data(beeswarmData)
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => height - margin.bottom - radius - padding - d.y)
.attr("r", radius)
.append("title")
.text(d => d.data.name);

return svg.node();
}
Insert cell
data = d3.csvParse(await FileAttachment("population.csv").text(), ({state, county, population: value}) => ({name: `${county}, ${state}`, value: +value}))
Insert cell
x = d3.scaleLog()
.domain(d3.extent(data, d => d.value))
.range([margin.left, width - margin.right])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x)
.ticks(width / 80)
.tickSizeOuter(0))
Insert cell
height = 480
Insert cell
radius = 2
Insert cell
padding = 1
Insert cell
margin = ({top: 20, right: 20, bottom: 30, left: 20})
Insert cell
d3 = require("d3@6")
Insert cell
AccurateBeeswarm = import("accurate-beeswarm-plot")
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