Function Repository Resource:

HypergraphPlot

Source Notebook

Plot a hypergraph defined by a list of hyperedges

Contributed by: Jaebum Jung

ResourceFunction["HypergraphPlot"][{{vi1,vi2,},}]

generates a plot of the hypergraph with hyperedges {{vi1,vi2,},}.

Details and Options

Hyperedges can be any expression.
The following options are supported:
"BaseLayout""SpringEmbedding"how to lay out vertices
"SubsetBoundary"Automaticwhether to draw the boundary of subsets
"SubsetBoundaryScale"2scale factor of the subset boundary size
"SubsetBoundaryStyle"Automaticstyles for subsets
"SubsetEdge"Automaticwhether to draw edges connecting vertices in subsets
"SubsetEdgeStyle"Automaticstyles for subset edges
PlotTheme“NameLabeled"overall theme for vertices
VertexCoordinatesAutomaticcenter coordinates for vertices
VertexLabelsNonelabels and placements for vertices
VertexLabelStyleAutomaticstyle to use for vertex labels
VertexShapeFunctionAutomaticgenerate graphic shapes for vertices
VertexSize0.15size of vertices
VertexStyleAutomaticstyles for vertices

Examples

Basic Examples (1) 

Draw a hypergraph:

In[1]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[1]=

Scope (2) 

Draw a hypergraph without edges connecting subsets:

In[2]:=
ResourceFunction[
 "HypergraphPlot"][{{1, 2, 3}, {2, 3, 5, 8}, {5, 7, 8}}, "SubsetBoundaryStyle" -> (Directive[Opacity[.5], EdgeForm[Black], #] & /@ ColorData[35, "ColorList"][[{2, 5, 10}]]), "SubsetBoundaryScale" -> {1.8, 2.5, 3}, "SubsetEdge" -> False]
Out[2]=

Draw a hypergraph with different vertex styles:

In[3]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundaryStyle" -> (Directive[Opacity[.5], EdgeForm[Black], #] & /@ ColorData[35, "ColorList"][[{2, 5, 10}]]), "SubsetBoundaryScale" -> {8, 10, 11}, "SubsetEdge" -> False, PlotTheme -> "Detailed", VertexSize -> .05, VertexStyle -> Black]
Out[3]=

Options (18) 

BaseLayout (2) 

The default base layout is "SpringEmbedding":

In[4]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[4]=

Use "RadialEmbedding":

In[5]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "BaseLayout" -> "RadialEmbedding"]
Out[5]=

SubsetBoundary (3) 

The default subset boundary is Automatic:

In[6]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[6]=

Use False to not show subset boundaries:

In[7]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundary" -> False]
Out[7]=

Alternate between True and False:

In[8]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundary" -> {True, False}]
Out[8]=

SubsetBoundaryScale (3) 

The default subset boundary scale factor is 2:

In[9]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[9]=

Increase the scale factor to 3:

In[10]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundaryScale" -> 3]
Out[10]=

Alternate between 3 and 5:

In[11]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundaryScale" -> {3, 5}]
Out[11]=

SubsetBoundaryStyle (3) 

The default subset boundary style is Automatic:

In[12]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[12]=

Use black boundary lines:

In[13]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundaryStyle" -> Directive[EdgeForm[Black], FaceForm[]]]
Out[13]=

Alternate between red and blue:

In[14]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetBoundaryStyle" -> {Red, Blue}]
Out[14]=

SubsetEdge (3) 

The default subset edge is Automatic:

In[15]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[15]=

Use False to not show subset edges:

In[16]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetEdge" -> False]
Out[16]=

Alternate between True and False:

In[17]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetEdge" -> {True, False}]
Out[17]=

SubsetEdgeStyle (3) 

The default subset edge style is Automatic:

In[18]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}]
Out[18]=

Use black edge lines:

In[19]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetEdgeStyle" -> Directive[Thickness[.02], Black]]
Out[19]=

Alternate between red and blue:

In[20]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, "SubsetEdgeStyle" -> {Red, Blue}]
Out[20]=

VertexCoordinates (1) 

Specify vertex coordinates:

In[21]:=
ResourceFunction["HypergraphPlot"][{{1, 2, 3}, {2, 3, 5}, {5, 7, 8}}, VertexCoordinates -> {1 -> {2, 1}, 2 -> {1, 0}, 3 -> {0, 1}, 5 -> {1, 2}, 7 -> {0, 3}, 8 -> {2, 3}}]
Out[21]=

Applications (2) 

Draw a hypergraph constructed by communities:

In[22]:=
ResourceFunction["HypergraphPlot"][
 FindGraphCommunities[
  ExampleData[{"NetworkGraph", "DolphinSocialNetwork"}]], VertexShapeFunction -> "Capsule", VertexSize -> 0.2]
Out[22]=

Pick the two most involved members of the terrorist network:

In[23]:=
g = ExampleData[{"NetworkGraph", "September11Terrorists"}]
Out[23]=
In[24]:=
names = MaximalBy[VertexList[g], VertexDegree[g, #] &, 2]
Out[24]=

Generate a hypergraph by members connected to most involved members:

In[25]:=
sets = VertexComponent[g, #, 1] & /@ names
Out[25]=

Show a hypergraph:

In[26]:=
ResourceFunction["HypergraphPlot"][sets, "SubsetBoundaryScale" -> {2, 3}]
Out[26]=

Version History

  • 2.1.0 – 12 September 2022
  • 2.0.0 – 09 March 2020
  • 1.0.0 – 15 November 2019

Related Resources

Author Notes

A prior function under this name was moved to the new name SimpleHypergraphPlot.

License Information