# Hierarchical Drawing of Directed Graphs

LayeredGraphPlot attempts to draw the vertices of a graph in a series of layers, placing dominant vertices at the top, and vertices lower in the hierarchy progressively further down.

LayeredGraphPlot[{v_{i1}->v_{j1},v_{i2}->v_{j2},…}] | |

generate a layered plot of the graph in which vertex is connected to vertex | |

LayeredGraphPlot[{{v_{i1}->v_{j1},lbl_{1}},…}] | |

associate labels with edges in the graph | |

LayeredGraphPlot[g,pos] | place the dominant vertices in the plot at position pos |

LayeredGraphPlot[m] | generate a layered plot of the graph represented by the adjacency matrix m |

LayeredGraphPlot draws a graph so that the edges point predominantly downward. The second argument of LayeredGraphPlot specifies the position of the root. Possible values for this argument are Right, Left, Top, and Bottom.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

LayeredGraphPlot may produce slightly different output on different platforms, due to floating‐point differences.

## Options for LayeredGraphPlot

In addition to options for Graphics, the following options are accepted for LayeredGraphPlot.

option name | default value | |

DataRange | Automatic | the range of vertex coordinates to generate |

DirectedEdges | True | whether to show edges as directed arrows |

EdgeLabeling | True | whether to include labels given for edges |

EdgeRenderingFunction | Automatic | function to give explicit graphics for edges |

MultiedgeStyle | Automatic | how to draw multiple edges between vertices |

PackingMethod | Automatic | method to use for packing components |

PlotRangePadding | Automatic | how much padding to put around the plot |

PlotStyle | Automatic | style in which objects are drawn |

SelfLoopStyle | Automatic | how to draw edges linking a vertex to itself |

VertexCoordinateRules | Automatic | rules for explicit vertex coordinates |

VertexLabeling | Automatic | whether to show vertex names as labels |

VertexRenderingFunction | Automatic | function to give explicit graphics for vertices |

Options for LayeredGraphPlot.

### DirectedEdges

The option DirectedEdges specifies whether to draw edges as arrows. Possible values for this option are True or False. The default value for this option is True.

In[3]:= |

Out[3]= |

### EdgeLabeling

The option EdgeLabeling specifies whether and how to display labels given for the edges. Possible values for this option are True, False, or Automatic. The default value for this option is True, which displays the supplied edge labels on the graph. With EdgeLabeling->Automatic, the labels are shown as tooltips.

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

_{i}->v

_{j},lbl] to specify a tooltip for an edge. Place the cursor over the edge between vertices 3 and 6, as well as the edge label on the edge between vertices 3 and 5, to see the tooltips.

In[6]:= |

Out[6]= |

### EdgeRenderingFunction

The option EdgeRenderingFunction specifies graphical representation of the graph edges. Possible values for this option are Automatic, None, or a function that gives a proper combination of graphics primitives and directives. With the default setting of Automatic, a dark red line is drawn for each edge. With EdgeRenderingFunction->None, edges are not drawn.

In[7]:= |

Out[7]= |

With EdgeRenderingFunction->g, each edge is rendered with the graphics primitives and directives given by the function g. It can take three or more arguments in the form , where , are the coordinates of the beginning and ending points of the edge, , are the beginning and ending vertices, and is any label specified for the edge or None. Explicit settings for EdgeRenderingFunction->g override settings for EdgeLabeling and DirectedEdges.

In[8]:= |

Out[8]= |

In[9]:= |

In[10]:= |

Out[10]= |

### MultiedgeStyle

The option MultiedgeStyle specifies whether to draw multiple edges between two vertices. Possible values for MultiedgeStyle are Automatic (the default), True, False, or a positive real number. With the default setting MultiedgeStyle->Automatic, multiple edges are shown for a graph specified by a list of rules, but not shown if the graph is specified by an adjacency matrix. With MultiedgeStyle->δ, the multiedges are spread out to a scaled distance of δ.

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

#### PackingMethod

The option PackingMethod specifies the method used for packing disconnected components. Possible values for the option are Automatic (the default), , , , , , and . With PackingMethod->"ClosestPacking", components are packed as close together as possible using a polyomino method [6], starting from the top left. With PackingMethod->"ClosestPackingCenter", components are packed starting from the center. With PackingMethod->"Layered", components are packed in layers starting from top left. With PackingMethod->"LayeredLeft" or PackingMethod->"LayeredTop", components are packed in layers starting from the top/left, respectively. With PackingMethod->"NestedGrid", components are arranged in a nested grid. The typical effective default setting is PackingMethod->"Layered", and the packing starts with components of the largest bounding box area.

In[14]:= |

Out[14]= |

In[15]:= |

Out[15]= |

### PlotRangePadding

PlotRangePadding is a common option for graphics functions inherited by LayeredGraphPlot.

### PlotStyle

PlotStyle is a common option for graphics functions inherited by LayeredGraphPlot. The option PlotStyle specifies the style in which objects are drawn.

In[16]:= |

Out[16]= |

### SelfLoopStyle

The option SelfLoopStyle specifies whether and how to draw loops for vertices that are linked to themselves. Possible values of the option are Automatic (the default), True, False, or a positive real number. With SelfLoopStyle->Automatic, self-loops are shown if the graph is specified by a list of rules, but not by an adjacency matrix. With SelfLoopStyle->δ, the self-loops are drawn with a diameter of δ (relative to the average edge length).

In[17]:= |

Out[17]= |

In[18]:= |

Out[18]= |

In[19]:= |

Out[19]= |

### VertexCoordinateRules

The option VertexCoordinateRules specifies the coordinates of the vertices. Possible values are None, or a list of coordinates. Coordinates specified by a list of rules are not currently supported by LayeredGraphPlot.

In[20]:= |

Out[20]= |

In[21]:= |

Out[21]= |

### VertexLabeling

The option VertexLabeling specifies whether to show vertex names as labels. Possible values for this option are True, False, Automatic (the default) and Tooltip. VertexLabeling->True shows the labels. For graphs specified by an adjacency matrix, vertex labels are taken to be successive integers , where n is the size of the matrix. For graphs specified by a list of rules, labels are the expressions used in the rules. VertexLabeling->False displays each vertex as a point. VertexLabeling->Tooltip displays each vertex as a point, but gives its name in a tooltip. VertexLabeling->Automatic displays each vertex as a point, giving its name in a tooltip if the number of vertices is not too large. You can also use Tooltip[v_{k},v_{lbl}] anywhere in the list of rules to specify an alternative tooltip for a vertex .

In[22]:= |

Out[22]= |

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

### VertexRenderingFunction

The option VertexRenderingFunction specifies graphical representation of the graph edges. Possible values for this option are Automatic, None, or a function that gives a proper combination of graphics primitives and directives. With the default setting of Automatic, vertices are displayed as points, with their names given in tooltips.

In[22]:= |

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

With VertexRenderingFunction->g, each vertex is rendered with the graphics primitives given by , where is the coordinate of the vertex and is the label of the vertex. Explicit settings for VertexRenderingFunction->g override settings for VertexLabeling.

In[27]:= |

Out[27]= |

## Example Gallery

### Flow Chart

LayeredGraphPlot helps visualize flow charts, for example for business, economic, or technical presentations.

In[28]:= |

Out[28]= |

In[29]:= |

Out[29]= |

### Food Chains

Food chains can be visualized with LayeredGraphPlot.

In[30]:= |

Out[30]= |

In[2]:= |

Out[2]= |

### History of Unix

LayeredGraphPlot is suitable for visualizing historical events.

In[32]:= |

Out[32]= |