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

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