Lab note
Random graph layout notes
A closer read of the layout behaviours that random graphs expose, and how to tell a good force-directed viewer from a brittle one using the random graph demo.
What this note is for
The random graph demo covers the basics. This note goes a layer deeper. It is about the layout behaviours that random graphs surface and how to read them.
If you only have time for one paragraph: a force-directed layout is a continuous negotiation between attraction along edges, repulsion between unrelated vertices, and damping. A random graph forces all three to compete at every density. That is why it is such a good test.
Sparse graphs and the repulsion limit
At very low edge probability, almost no two vertices are connected. The repulsion force is the only thing the layout has to work with. The picture spreads the vertices out as evenly as possible.
The behaviour to watch:
- Does the layout reach a stable arrangement, or do the vertices drift forever?
- If you add a single edge, does the picture absorb it gracefully or yank the connected vertices toward each other?
A layout that fails at sparse graphs usually has weak damping. The picture never settles because repulsion is the dominant force and there is nothing to keep it from oscillating.
The cluster transition
As edges accumulate, the picture stops looking uniform and starts forming clusters. The clusters are real - they reflect the connectivity of the graph - but they are not stable. A random graph has no preferred clustering. The clusters you see at one moment are not the same clusters you would see if the layout restarted.
Two things to watch in this regime:
- The picture should be readable but not still. A layout that is still here has settled too aggressively. A layout that is hectic here has damping that is too weak.
- The clusters should move slowly. If they rearrange quickly without an underlying change in the graph, the layout is reacting to noise rather than structure.
This is the most interesting regime to watch. The picture has structure but it does not have a preferred orientation. A good viewer keeps the picture readable and admits that the structure is approximate.
The dense end
Past a certain density, the layout cannot keep the vertices separated. The picture becomes a tight cluster. Edges run through the middle of the cluster and become hard to read.
A layout’s behaviour at the dense end is not really a layout question - it is a rendering question. The layout is doing what it can. The renderer has to decide what to draw.
Two things help at high density:
- Reducing edge opacity so that the cluster reads as a volume rather than a solid object.
- Hiding labels and letting the reader focus on shape.
Neither of these is the layout’s job. They are presentation choices.
Reading the response to a change
The most informative thing you can do with the demo is move the probability slider and watch the response. A few specific tests:
- Small increase from sparse. A few new edges arrive. The picture should adjust by pulling the affected pairs together. The rest of the picture should not move noticeably.
- Large increase, fast. Many edges arrive at once. The picture should rearrange smoothly. A viewer that flickers here is the wrong viewer for animation.
- Decrease from medium. Edges disappear. The picture should relax outward. A viewer that holds the previous shape too long is over-damped.
You can learn most of what you need to know about a force-directed viewer in two minutes of moving the slider.
What random graphs are not
A random graph is not a model of any real network. Real networks have heavier tails (a few highly connected vertices), more local structure (triangles are more common than chance), and more correlation between neighbours.
The random graph demo is not lying about this. It is doing what it says it does: connecting pairs of vertices at a uniform probability. The point is to see the layout under a known structure, not to claim the structure is realistic.
If you want to see a viewer under a more realistic load, the random binary tree demo is closer to a real structural test, and the animation demo is closer to a real workload.
A small parameter to remember
Most layouts have an effective length for an edge - a distance at which the spring force is at rest. This length is the single most important layout parameter and is usually buried in the configuration.
If you find a layout that produces unreadable random graphs at moderate density, the first thing to try is increasing the resting edge length. The picture spreads out and the clusters become legible. If that does not help, the second thing to try is increasing the repulsion strength.
Those two knobs cover most of the practical layout tuning you will need on a random graph.
Where this connects in the rest of the site
- Random graph demo - the picture this note is reading.
- Demos index - the full demo set.
- Graph visualisation alternatives - viewer choices that affect this behaviour.
- Ubigraph pillar page - the broader context.