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[{vi1->vj1,vi2->vj2,…}] | |
generate a layered plot of the graph in which vertex vik is connected to vertex vjk | |
LayeredGraphPlot[{{vi1->vj1,lbl1},…}] | |
associate labels lblk 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.
LayeredGraphPlot may produce slightly different output on different platforms, due to floating‐point differences.
option name | default value | |
DataRange | Automatic | the range of vertex coordinates to generate |
DirectedEdges | True | whether to show edges as directed arrows |
EdgeLabels | Automatic | whether to include labels given for edges |
EdgeShapeFunction | Automatic | function to give explicit graphics for edges |
MultiedgeStyle | Automatic | how to draw multiple edges between vertices |
"PackingLayout" | 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 |
VertexCoordinates | Automatic | rules for explicit vertex coordinates |
VertexLabels | Automatic | whether to show vertex names as labels |
VertexShapeFunction | 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.
EdgeLabels
The option EdgeLabels specifies whether and how to display labels given for the edges. Possible values for this option are All, None and Automatic. The default value for this option is Automatic, which displays the supplied edge labels on the graph.
Use Tooltip[vi->vj,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:
EdgeShapeFunction
The option EdgeShapeFunction 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 EdgeShapeFunction->None, edges are not drawn.
With EdgeShapeFunction->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 g[{ri,…,rj},{vi,vj},lblij,…], where ri, rj are the coordinates of the beginning and ending points of the edge, vi, vj are the beginning and ending vertices, and lblij is any label specified for the edge or None. Explicit settings for EdgeShapeFunction->g override settings for EdgeLabels and DirectedEdges.
This plots edges as gray arrows with ends set back from vertices by a distance of 0.3 (in the graph's coordinate system):
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 δ.
PackingLayout
The option "PackingLayout" specifies the method used for packing disconnected components. Possible values for the option are Automatic (the default), "ClosestPacking", "ClosestPackingCenter", "Layered", "LayeredLeft", "LayeredTop", and "NestedGrid". With "PackingLayout"->"ClosestPacking", components are packed as close together as possible using a polyomino method [6], starting from the top left. With "PackingLayout"->"ClosestPackingCenter", components are packed starting from the center. With "PackingLayout"->"Layered", components are packed in layers starting from top left. With "PackingLayout"->"LayeredLeft" or "PackingLayout"->"LayeredTop", components are packed in layers starting from the top/left, respectively. With "PackingLayout"->"NestedGrid", components are arranged in a nested grid. The typical effective default setting is "PackingLayout"->"Layered", and the packing starts with components of the largest bounding box area.
PlotRangePadding
PlotStyle
PlotStyle is a common option for graphics functions inherited by LayeredGraphPlot. The option PlotStyle specifies the style in which objects are drawn.
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).
VertexCoordinates
The option VertexCoordinates specifies the coordinates of the vertices. Possible values are None, or a list of coordinates.
VertexLabels
The option VertexLabels specifies whether to show vertex names as labels. Possible values for this option are All, None and Automatic (the default). VertexLabels->All 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. VertexLabels->None displays each vertex as a point. You can also use Tooltip[vk,vlbl] anywhere in the list of rules to specify an alternative tooltip for a vertex vk.
This plots vertices as points, and displays vertex names in tooltips. Place the cursor above the vertices to see the labels:
VertexShapeFunction
The option VertexShapeFunction 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 VertexShapeFunction->g, each vertex is rendered with the graphics primitives given by g[ri,vi,…], where ri is the coordinate of the vertex and vi is the label of the vertex. Explicit settings for VertexShapeFunction->g override settings for VertexLabels.
Flow Chart
LayeredGraphPlot helps visualize flow charts, for example for business, economic, or technical presentations.
Food Chains
Food chains can be visualized with LayeredGraphPlot.
History of Unix
LayeredGraphPlot is suitable for visualizing historical events.