Published
Edited
Sep 15, 2021
1 fork
1 star
Insert cell
md`# Beeswarm Plot`
Insert cell
Insert cell
Insert cell
viewof clusters = slider({min: 3, max:9, step:1, title: "Number of clusters"})
Insert cell
viewof height = slider({min: "150", max: 200, step:10, title: "Height:"})
Insert cell
Insert cell
Insert cell
md`# Utils`
Insert cell
colorScale = ({
quantileScale,
quantizeScale,
clusterScale
})
Insert cell
quantileScale = d3.scaleQuantile()
.domain(data.map(d => d.value))
.range(d3.schemeRdYlBu[clusters]);
Insert cell
quantizeScale = d3.scaleQuantize()
.domain(d3.extent(data.map(d => d.value)))
.range(d3.schemeRdYlBu[clusters]);
Insert cell
clusterScale = scaleCluster()
.domain(data.map(d => d.value))
.range(d3.schemeRdYlBu[clusters]);
Insert cell
radius = 3
Insert cell
padding = 1
Insert cell
xScale = d3.scaleLinear()
.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(xScale))
Insert cell
simulation = {
const simulation = d3.forceSimulation(data)
.force("x", d3.forceX(d => xScale(d.value)).strength(1))
.force("y", d3.forceY(height / 2))
.force("collide", d3.forceCollide(radius + padding))
.stop()
for (let i = 0; i < 120; ++i) {
simulation.tick();
}
return simulation
}
Insert cell
Insert cell
Insert cell
md`# Library`
Insert cell
d3 = require("d3@6")
Insert cell
scaleCluster = require("d3-scale-cluster")
Insert cell
import {slider, radio, text, select, color} from '@jashkenas/inputs'
Insert cell
md`## Reference
`
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