|Graph Theory Notations||Selecting the Appropriate Graph Drawing Function|
|Graph Drawing Algorithms|
The Wolfram Language provides functions for the aesthetic drawing of graphs. Algorithms implemented include spring embedding, spring-electrical embedding, high-dimensional embedding, radial drawing, random embedding, circular embedding, and spiral embedding. In addition, algorithms for layered/hierarchical drawing of directed graphs as well as for the drawing of trees are available. These algorithms are implemented via four functions: GraphPlot, GraphPlot3D, LayeredGraphPlot, and TreePlot.
|GraphPlot||generate a plot of a graph|
|GraphPlot3D||generate a 3D plot of a graph|
|LayeredGraphPlot||generate a layered plot of a graph|
|TreePlot||generate a tree plot of a graph|
GraphPlot and GraphPlot3D are suitable for straight line drawing of general graphs. LayeredGraphPlot attempts to draw the vertices of a graph in a series of layers; therefore it is most suitable for applications such as the drawing of flow charts. TreePlot is particularly useful for drawing trees or tree-like graphs. These functions are designed to work efficiently for very large graphs.
In these functions, a graph is represented either by a list of rules of the form , where and are vertices, or by the adjacency matrix of the graph. Graphs in the Combinatorica package format are also supported.
If implies that , then is an undirected graph. Otherwise it is a directed graph. The former can be drawn using line segments, while the latter can be drawn with arrows. In an undirected graph, it is often convenient to denote that an edge exists between and with the notation .
A graph can also be represented by its adjacency matrix. Let be a directed graph. Assuming that the vertices are indices from to , that is, , then the adjacency matrix of is an × matrix, with entries if and otherwise.
Because of the zero entries in an adjacency matrix, it is often convenient to represent the matrix using a SparseArray.
GraphPlot uses the algorithms described in the next section to lay out a graph. If GraphPlot is to be used for a graph in Combinatorica format, but the drawing assigned by Combinatorica is to be preserved, Method->None can be specified.
Graphs are often used to encapsulate the relationship between items. Graph drawing enables visualization of these relationships. The usefulness of the visual representation depends upon whether the drawing is aesthetic. While there are no strict criteria for aesthetic drawing, it is generally agreed that such a drawing has minimal edge crossing and even spacing between vertices. This problem has been studied extensively in the literature , and many approaches have been proposed. Two popular straight-edge drawing algorithms, the spring embedding and spring-electrical embedding, work by minimizing the energy of physical models of the graph. The high-dimensional embedding method, on the other hand, embeds a graph in high-dimensional space and then projects it back to two- or three-dimensional space. In addition, there are algorithms for drawing directed graphs in a hierarchical fashion, as well as for drawing trees. Random embedding, circular embedding, and spiral embedding do not utilize any connectivity information for laying out a graph, and therefore are not described any further here.
The spring embedding algorithm assigns force between each pair of nodes. When two nodes are too close together, a repelling force comes into effect. When two nodes are too far apart, they are subject to an attractive force. This scenario can be illustrated by linking the vertices with springs—hence the name "spring embedding".
Here, and are the coordinate vectors of nodes and , and is the Euclidean distance between them. is the natural length of the spring between vertex and vertex , and can be chosen as the graph distance between and . The parameters are the strength of the springs, where is a parameter representing the strength of the springs. is the number of vertices.
The layout of the graph vertices is calculated by minimizing this energy function. One way to minimize the energy function is by iteratively moving each of the vertices along the direction of the spring force until an approximate equilibrium is reached. Multilevel techniques are used to overcome local minima.
Spring embedding works particularly well for problems like regular grid graphs, in which it is possible to lay out the graph so that Euclidean distances between vertices are proportional to the graph distances.
This method does, however, require more memory and CPU time. To reduce its complexity, vertices that are far apart are ignored in the calculation of force and energy. See the method option of GraphPlot and GraphPlot3D for more information.
The disadvantage of the spring embedding algorithm is that it requires knowing the graph distance between every pair of vertices. Spring-electrical embedding uses two forces. The attractive force, , is restricted to adjacent vertices and is proportional to the Euclidean distance between them, where is related to the natural spring length. The electrical force, , on the other hand, is global and is inversely proportional to the Euclidean distance between nodes and . Overall, the energy to be minimized is , where
Here, is a constant that regulates the relative strength of the repulsive and attractive forces, and is the Euclidean distance between nodes and . For a graph of two vertices, the ideal Euclidean distance between the vertices is , which gives a total energy of zero.
The layout of the graph vertices is calculated by minimizing the energy function. One way to do this is by iteratively moving each of the vertices along the direction of the spring force until an approximate equilibrium is reached. Multilevel techniques  are used to overcome local minima, and an octree data structure  is used to reduce the computational complexity in some cases.
A side effect of this algorithm is that vertices at the periphery tend to be closer to each other than those in the center, as seen in the previous drawing. This tendency can be alleviated with the method option , which is described in "General Graph Drawing".
In the high-dimensional embedding method, a graph is embedded in high-dimensional space, and then projected back to two- or three-dimensional space. First, a -dimensional coordinate system is created based on centers. The centers are a set of vertices that are chosen to be as far apart as possible. The first vertex is selected at random, and then each of the remaining centers is chosen as the farthest vertex from the previously selected centers. In other words, if centers have been selected, is the vertex whose shortest graph distance to the centers is larger than or equal to the shortest graph distance of all the other vertices to the centers.
With these centers, a -dimensional coordinate system can be established. Each vertex has the coordinates , where is the graph distance between the vertex and the center . The -dimensional coordinate vectors form an × matrix , where is the row of .
Since it is only possible to draw in two and three dimensions, and since the coordinates are correlated, the -dimensional coordinates are projected back to two or three dimensions by a suitable linear combination. Assume that the graph with coordinates and centers is projected back to two dimensions. In order to make this projection shift-invariant, is first normalized to .
To achieve this, you therefore select and to be the two eigenvectors that correspond to the first two largest eigenvalues of the × symmetric matrix . This process of choosing two highly uncorrelated vectors is also known as principal component analysis.
The high-dimensional embedding method tends to be very fast but its results are often of lower quality than force-directed algorithms. The method can be specified with Method->"HighDimensionalEmbedding" in GraphPlot and GraphPlot3D.
1. Vertices of the DAG are first assigned a preliminary ranking such that if there is an edge from to , then it is likely that . This is to ensure that the final drawing has directed edges pointing mostly downward.
2. The coordinates are generated so that if there is an edge from to and , their coordinates are as close as possible, but separated by a set minimum. This ensures that the final resulting drawing does not have many long edges. This process assigns the vertices into a finite number of layers. If an edge lies across a number of layers, virtual vertices are added.
The resulting drawing lays out the graph in a hierarchical structure, where most of the edges point downward. LayeredGraphPlot function implements this algorithm.
Two algorithms for drawing trees are the radial drawing algorithm and the layered drawing algorithm . In the radial drawing algorithm, a reasonable root of the tree is chosen. Then, starting from that root of the tree, each subtree is drawn inside a wedge, with the angle of the wedge proportional to the number of leaves in that subtree. In the layered drawing algorithm, a reasonable root of the tree is chosen. Then, starting from that root, subtrees of the root are recursively drawn such that vertices on the same level have the same coordinate, and the horizontally closest vertices of adjacent subtrees are of unit distance apart. The root is placed at the center of the coordinates of its subtrees and its coordinate is one unit above them. TreePlot function chooses between these two algorithms, depending on the second argument of this function.
For general graph drawing, consider using GraphPlot or GraphPlot3D. GraphPlot or GraphPlot3D calculates a visually appealing 2D/3D layout and plots the graph using this layout. See "General Graph Drawing" for these functions, and  for algorithmic details.
To get a layered/hierarchical drawing of a directed graph, use LayeredGraphPlot. LayeredGraphPlot attempts to draw the vertices of a graph in a series of layers, with dominant vertices at the top, and vertices lower in the hierarchy progressively farther down. This function is most suitable for applications such as flow chart drawing. See "Hierarchical Drawing of Directed Graphs" for this function.
 Lim, A., B. Rodrigues, and F. Xiao. "A Centroid-Based Approach to Solve the Bandwidth Minimization Problem." In Proceedings of the 37th Annual Hawaii International Conference on System Sciences (HICSS'04), 30075.1, 2004.
 Quigley, A. "Large Scale Relational Information Visualization, Clustering, and Abstraction." PhD Thesis, Department of Computer Science and Software Engineering, University of Newcastle, Australia, 2001.