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.
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
).
Available on crates.io.
bash
:dep chord = {Version = "0.1.1"}
use chord::{Chord, Plot};
You can see the actual interactive examples on this page. The below examples are screenshots.
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.
```rust
let matrix: Vec
let names: Vec
Let's see what the Chord
defaults produce when we invoke the show()
method.
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
..Chord::default()
}
.show();
You can also save it to a HTML file.
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
..Chord::default()
}
.to_html();
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.
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
colors: "d3.schemeSet2".to_string(),
..Chord::default()
}
.show();
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
colors: format!("d3.schemeGnBu[{:?}]",names.len()).to_string(),
..Chord::default()
}
.show();
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
colors: "d3.schemeSet3".to_string(),
..Chord::default()
}
.show();
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
colors: format!("d3.schemePuRd[{:?}]",names.len()).to_string(),
..Chord::default()
}
.show();
python
Chord {
matrix: matrix.clone(),
names: names.clone(),
colors: format!("d3.schemeYlGnBu[{:?}]",names.len()).to_string(),
..Chord::default()
}
.show();
```rust
let hexcolours : Vec
Chord { matrix: matrix.clone(), names: names.clone(), colors: format!("{:?}",hex_colours), ..Chord::default() } .show(); ```
We can disable the wrapped labels, and even change the colour.
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
wrap_labels: false,
label_color:"#4c40bf".to_string(),
..Chord::default()
}
.show();
We can also change the default opacity of the relationships.
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
opacity: 0.1,
..Chord::default()
}
.show();
We can change the maximum diagram size by specifying a width.
rust
Chord {
matrix: matrix.clone(),
names: names.clone(),
width: 400.0,
..Chord::default()
}
.show()
Tintarev, N., Rostami, S., & Smyth, B. (2018, April). Knowing the unknown: visualising consumption blind-spots in recommender systems. In Proceedings of the 33rd Annual ACM Symposium on Applied Computing (pp. 1396-1399). ↩
chord
(Python), Shahin Rostami.chord
(Rust), Shahin Rostami.