Function Repository Resource:

ChordDiagram

Source Notebook

Make a weighted connectivity graph using circular embedding

Contributed by: Georgios Varnavides

ResourceFunction["ChordDiagram"][graph]

generates a chord diagram using a weighted graph.

Details and Options

ResourceFunction["ChordDiagram"] requires an edge-weighted graph as input.
ResourceFunction["ChordDiagram"] draws each vertex of the weighted graph as a wedge, with width proportional to its WeightedAdjacencyMatrix row total.
ResourceFunction["ChordDiagram"] draws a ribbon made from two Poincaré arcs for each directed edge.
The following options can be specified:
"Labels"Automaticchoose the vertex labels
"Colors"Automaticchoose the ribbon colors for each edge
"BackgroundOpacity"0.25set the background ribbon opacity
"Interactive"Falseinclude interactive mouseover
"TrimEdges"0trim edges with small weights
Use "TrimEdges"n to avoid multiple thin ribbons in the resulting graphic.
"Labels"Automatic uses the vertex labels given by VertexList[graph].
"Colors"Automatic uses random colors.

Examples

Basic Examples (1) 

A chord diagram with simple weighted graph:

In[1]:=
wg = Graph[{1 \[DirectedEdge] 3, 1 \[DirectedEdge] 2, 2 \[DirectedEdge] 1, 3 \[DirectedEdge] 2, 3 \[DirectedEdge] 1}, EdgeWeight -> {1, 2, 1, 3, 2}];
ResourceFunction["ChordDiagram"][wg]
Out[1]=

Options (5) 

Labels (2) 

By default, ChordDiagram uses VertexList as labels:

In[2]:=
wg = Graph[{1 \[DirectedEdge] 3, 1 \[DirectedEdge] 2, 2 \[DirectedEdge] 1, 3 \[DirectedEdge] 2, 3 \[DirectedEdge] 1}, EdgeWeight -> {1, 2, 1, 3, 2}];
In[3]:=
VertexList[wg]
Out[3]=
In[4]:=
ResourceFunction["ChordDiagram"][wg]
Out[4]=

Use an explicit list of strings to overwrite this:

In[5]:=
wg = Graph[{1 \[DirectedEdge] 3, 1 \[DirectedEdge] 2, 2 \[DirectedEdge] 1, 3 \[DirectedEdge] 2, 3 \[DirectedEdge] 1}, EdgeWeight -> {1, 2, 1, 3, 2}];
ResourceFunction["ChordDiagram"][wg, "Labels" -> {"A", "B", "C"}]
Out[5]=

TrimEdges (2) 

For realistic datasets, many edges may suffer from small weights:

In[6]:=
wg = ExampleData[{"NetworkGraph", "LesMiserables"}];
ResourceFunction["ChordDiagram"][wg]
Out[6]=

Use TrimEdges to drop the lowest edge weights:

In[7]:=
ResourceFunction["ChordDiagram"][wg, "TrimEdges" -> 5]
Out[7]=

Interactive (1) 

Add basic interactivity using mouseovers:

In[8]:=
wg = ExampleData[{"NetworkGraph", "LesMiserables"}];
ResourceFunction["ChordDiagram"][wg, "TrimEdges" -> 5, "Interactive" -> True]
Out[8]=

Applications (2) 

Using a directed graph to show asymmetric ribbon widths:

In[9]:=
wg = ExampleData[{"NetworkGraph", "EurovisionVotes"}];

Add custom colors and labels:

In[10]:=
labels = CountryData[#, "CountryCode"] & /@ VertexList[wg];
flags = CountryData[#, "Flag"] & /@ VertexList[wg];
cols = Most@*Blend@*DominantColors /@ flags;
In[11]:=
ResourceFunction["ChordDiagram"][wg, "Labels" -> labels, "Colors" -> cols]
Out[11]=

Properties and Relations (1) 

By default, the function accepts a weighted graph. If you instead have a weighted adjacency matrix, this can be converted to a weighted graph first:

Out[25]=
In[26]:=
MatrixForm[
 wam = ReplacePart[
   RandomInteger[{0, 10}, {5, 5}], {i_, i_} :> \[Infinity]]]
In[27]:=
wg = WeightedAdjacencyGraph[wam]
Out[27]=
In[28]:=
ResourceFunction["ChordDiagram"][wg]
Out[28]=

Publisher

Georgios Varnavides

Version History

  • 1.0.0 – 08 August 2019

License Information