Introduction
In a chord diagram (or radial network), entities are arranged radially as segments with their relationships visualised by arcs that connect them. The size of the segments illustrates the numerical proportions, whilst the size of the arc illustrates the significance of the relationships1.
Chord diagrams are useful when trying to convey relationships between different entities, and they can be beautiful and eye-catching.
The Chord Crate
I wasn't able to find any Rust crates for plotting chord diagrams, so I ported my own from Python to Rust.
You can get the package either from crates.io or from the GitHub repository. With your processed data, you should be able to plot something beautiful with just a single line, Chord{ matrix : matrix, names : names, .. Chord::default() }.show()
The primary support is for Jupyter Lab
(not the older Jupyter Notebook
).
Installation
Available on crates.io.
;
Examples
You can see the actual interactive examples on this page. The below examples are screenshots.
The Dataset
The focus for this section will be the demonstration of the chord
package. To keep it simple, we will use synthetic data that illustrates the co-occurrences between movie genres within the same movie.
let matrix: = vec!;
let names: = vec!
.into_iter
.map
.collect;
Default Settings
Let's see what the Chord
defaults produce when we invoke the show()
method.
Chord .show;
You can also save it to a HTML file.
Chord .to_html;
Different Colours
The defaults are nice, but what if we want different colours? You can pass in almost anything from d3-scale-chromatic, or you could pass in a list of hexadecimal colour codes.
Chord .show;
Chord .show;
Chord .show;
Chord .show;
;
let hex_colours : = vec!.into_iter
.map
.collect;
Chord
.show;
Label Styling
We can disable the wrapped labels, and even change the colour.
Chord .show;
Opacity
We can also change the default opacity of the relationships.
Chord .show;
Diagram Size
We can change the maximum diagram size by specifying a width.
Chord .show
Credits
- d3-chord, Mike Bostock.
- d3-chord gradient fills, Nadieh Bremer.
chord
(Python), Shahin Rostami.chord
(Rust), Shahin Rostami.