Wolfram Research

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" Automatic choose the vertex labels
"Colors" Automatic choose the ribbon colors for each edge
"BackgroundOpacity" 0.25 set the background ribbon opacity
"Interactive" False include interactive mouseover
"TrimEdges" 0 trim 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

A chord diagram with a 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[2]=

Options

Labels

By default, ChordDiagram uses VertexList as labels:

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

Use an explicit list of strings to overwrite this:

In[6]:=
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[7]=

TrimEdges

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

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

Use "TrimEdges" to drop the lowest edge weights:

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

Interactive

Add basic interactivity using mouseovers:

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

Applications

Use a directed graph to show asymmetric ribbon widths:

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

Add custom colors and labels:

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

Properties and Relations

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:

In[16]:=
MatrixForm[
 wam = ReplacePart[
   RandomInteger[{0, 10}, {5, 5}], {i_, i_} :> \[Infinity]]]
Out[16]=
In[17]:=
wg = WeightedAdjacencyGraph[wam]
Out[17]=
In[18]:=
ResourceFunction["ChordDiagram"][wg]
Out[18]=

Resource History

Source Metadata

License Information