A beeswarm plot shows a distribution without hiding its individual data points. Each point sits near the position for its value, while nearby points shift to avoid overlapping. The result makes both the overall shape and the individual observations visible. section 12.4.1
Build one with a D3 force simulation:
- Create one node per observation and draw each node as an SVG circle. section 12.4.1
- Use forceX(d => xScale(d.value)) to pull each circle toward its value on the horizontal axis. Use forceY(0) to pull circles toward the vertical center. section 12.4.1
- Add forceCollide().radius(7) to keep circles apart, then update their displayed positions on each simulation tick. section 12.4.1
A distribution of 300 values
Generate 300 values with d3.randomNormal(), then apply the three forces to their circles. The resulting swarm reveals the normal distribution while retaining every point. Treat the horizontal positions as approximate: the simulation balances the value-positioning force against centering and collision, so a circle may not land exactly at its value. section 12.4.1
Figure 12.15 Beeswarm plot representing normally distributed values
The finished plot shows how individual points remain visible within the distribution. section 12.4.1

