Wolfram Research

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" Automatic whether to draw the boundary of subsets
"SubsetBoundaryScale" 2 scale factor of the subset boundary size
"SubsetBoundaryStyle" Automatic styles for subsets
"SubsetEdge" Automatic whether to draw edges connecting vertices in subsets
"SubsetEdgeStyle" Automatic styles for subset edges
PlotTheme "IndexLabeled" overall theme for vertices
VertexLabels None labels and placements for vertices
VertexLabelStyle Automatic style to use for vertex labels
VertexShapeFunction Automatic generate graphic shapes for vertices
VertexSize 0.15 size of vertices
VertexStyle Automatic styles for vertices

Examples

Basic Examples

Draw a hypergraph:

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

Scope

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

BaseLayout

The default base layout is "SpringEmbedding":

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

Use "RadialEmbedding":

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

SubsetBoundary

The default subset boundary is Automatic:

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

Use False to not show subset boundaries:

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

Alternate between True and False:

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

SubsetBoundaryScale

The default subset boundary scale factor is 2:

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

Increase the scale factor to 3:

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

Alternate between 3 and 5:

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

SubsetBoundaryStyle

The default subset boundary style is Automatic:

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

Use black boundary lines:

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

Alternate between red and blue:

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

SubsetEdge

The default subset edge is Automatic:

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

Use False to not show subset edges:

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

Alternate between True and False:

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

SubsetEdgeStyle

The default subset edge style is Automatic:

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

Use black edge lines:

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

Alternate between red and blue:

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

Applications

Draw a hypergraph constructed by communities:

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

Pick the two most involved members of the terrorist network:

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

Generate a hypergraph by members connected to most involved members:

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

Show a hypergraph:

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

Resource History

Related Resources

Author Notes

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

License Information