General Graph Drawing

(RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]) calculate and plot a visually appealing 2D/3D layout of a graph. The functions are designed to work with very large graphs and handle both connected and disconnected graphs.

Graph drawing functions.

This plots a graph specified by a rule list:

GraphPlot[{"d"->"c","e"->"b","e"->"c","e"->"d","f"->"a","f"->"b","f"->"d","f"->"e","g"->"a","g"->"b","g"->"c","g"->"e"},VertexLabeling->True]

For disconnected graphs, individual components are laid out in a visually appealing way and assembled:

GraphPlot[Table[i->Mod[i^2,129],{i,0,128}]]

This is a larger graph defined by a sparse adjacency matrix from a structural engineering application. The matrix comes from the (WebLink[Harwell–Boeing Collection, http://math.nist.gov/MatrixMarket/data/Harwell-Boeing/dwt/dwt_1005.html]):

a=Import["LinearAlgebraExamples/Data/dwt_1005.psa","HarwellBoeing"];

GraphPlot3D[a,VertexRenderingFunction->None]

(RefLink[GraphPlot, paclet:ref/GraphPlot]) may produce slightly different output on different platforms, due to floating-point differences.

Options for GraphPlot and GraphPlot3D

The following options are accepted for (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]) ((RefLink[DirectedEdges, paclet:ref/DirectedEdges]) and (RefLink[EdgeLabeling, paclet:ref/EdgeLabeling]) options are only valid for (RefLink[GraphPlot, paclet:ref/GraphPlot])), in addition, options for (RefLink[Graphics, paclet:ref/Graphics]) and (RefLink[Graphics3D, paclet:ref/Graphics3D]) are accepted.

Options for (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]).

DirectedEdges

The option (RefLink[DirectedEdges, paclet:ref/DirectedEdges]) specifies whether to draw edges as arrows. Possible values for this option are (RefLink[True, paclet:ref/True]) or (RefLink[False, paclet:ref/False]). The default value for this option is (RefLink[False, paclet:ref/False]).

This shows a graph with edges represented by arrows:

GraphPlot[{1->6,2-> 6,3-> 6,4-> 6,5-> 6},DirectedEdges-> True,VertexLabeling -> True]

This makes the arrowheads larger:

Table[
GraphPlot[{1->6,2-> 6,3-> 6,4-> 6,5-> 6},ImageSize->100,DirectedEdges-> {True,"ArrowheadsSize"->asize},VertexLabeling -> True],{asize,{0.05,0.1,0.15}}]

EdgeLabeling

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

By default, (RefLink[GraphPlot, paclet:ref/GraphPlot]) displays the supplied label for the edge between vertices 3 and 6:

GraphPlot[{1->5,1->6,2->4,2->6,3->4,3->5,{3->6, "edge 3->6"},4->6,5->6},VertexLabeling-> True]

This displays the edge label as a tooltip. Place the cursor over the edge between vertices 3 and 6 to see the tooltip:

GraphPlot[{1->5,1->6,2->4,2->6,3->4,3->5,{3->6, "edge 3->6"},4->6,5->6},EdgeLabeling-> Automatic,VertexLabeling-> True]

Alternatively, use (RefLink[Tooltip, paclet:ref/Tooltip])[(Subscript[v, i])->(Subscript[v, j]),lbl] to specify a tooltip for an edge. Place the cursor over the edge between vertices 3 and 6, as well as over the edge label on the edge between vertices 3 and 5, to see the tooltips:

GraphPlot[{1->5,1->6,2->4,2->6,3->4,{3->5,Tooltip[ "edge 3->5","3->5"]},Tooltip[3->6, "3->6"],4->6,5->6},VertexLabeling-> True]

To display the supplied label for the edge in 3D, (RefLink[EdgeRenderingFunction, paclet:ref/EdgeRenderingFunction]) needs to be used. This is described in "Edge Rendering Function".

EdgeRenderingFunction

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

This draws vertices only:

GraphPlot[Table[1,{30},{30}], EdgeRenderingFunction->None]

With (RefLink[EdgeRenderingFunction, paclet:ref/EdgeRenderingFunction])->g, each edge is rendered with the graphics primitives and directives given by the function g that can take three or more arguments, in the form g[{(Subscript[r, i]),…,(Subscript[r, j])},{(Subscript[v, i]),(Subscript[v, j])},(Subscript[lbl, ij]),…], where (Subscript[r, i]), (Subscript[r, j]) are the coordinates of the beginning and ending points of the edge, (Subscript[v, i]), (Subscript[v, j]) are the beginning and ending vertices, and (Subscript[lbl, ij]) is any label specified for the edge or (RefLink[None, paclet:ref/None]). Explicit settings for (RefLink[EdgeRenderingFunction, paclet:ref/EdgeRenderingFunction])->g override settings for (RefLink[EdgeLabeling, paclet:ref/EdgeLabeling]) and (RefLink[DirectedEdges, paclet:ref/DirectedEdges]).

This plots the edges as gray arrows with ends set back from vertices by a distance 0.1 (in the graph's coordinate system):

GraphPlot[{1->2,2->3,3->4,4->5,5->6,6->7,7->1,11->12,12->13,13->14,14->15,15->16,16->17,17->11,1->11,2->12,3->13,4->14,5->15,6->16,7->17},EdgeRenderingFunction->({GrayLevel[0.5], Arrow[#1,0.1]}&)]

This generates edge labels or displays the ones supplied in the description of the graph:

GraphPlot[{1->5,1->6,2->4,2->6,3->4,3->5,{3->6,"edge 3->6"},4->6,5->6},EdgeRenderingFunction->({{Red,Line[#1]},Text[If[#3===None,#2,#3],Total[#1]/2.,Background->White]}&),VertexLabeling->True]

This draws straight edges in black and other edges (two multiedges and a self-loop) in red. The function (PackageLink[LineScaledCoordinate, paclet:GraphUtilities/ref/LineScaledCoordinate, GraphUtilities Package Symbol]) from the package GraphUtilities is used to place labels at 70% of the length of the edge:

<<GraphUtilities`

GraphPlot3D[{1->2, 2->3, 3->4, 5->1, 5->2, 5->3, 5->4,1->4,3->5,3->3},EdgeRenderingFunction->(If [Length[#1]>2,{Red,Line[#1],Text[If[First[#1]===Last[#1],"loop","multiedge"],LineScaledCoordinate[#1,.7],Background->White]},Line[#1]]&),VertexLabeling->True]

This plots a 3D graph using spheres for vertices and cylinders for edges:

GraphPlot3D[{2->1,5->1,6->1,3->2,11->2,4->3,16->3,5->4,21->4,26->5,7->6,10->6,8->7,30->7,9->8,42->8,10->9,38->9,12->10,12->11,15->11,13->12,14->13,37->13,15->14,33->14,17->15,17->16,20->16,18->17,19->18,32->18,20->19,53->19,22->20,22->21,25->21,23->22,24->23,52->23,25->24,48->24,27->25,27->26,30->26,28->27,29->28,47->28,30->29,43->29,32->31,35->31,54->31,33->32,34->33,35->34,36->34,56->35,37->36,40->36,38->37,39->38,40->39,41->39,57->40,42->41,45->41,43->42,44->43,45->44,46->44,58->45,47->46,50->46,48->47,49->48,50->49,51->49,59->50,52->51,55->51,53->52,54->53,55->54,60->55,57->56,60->56,58->57,59->58,60->59},EdgeRenderingFunction->({Cylinder[#1,.1]}&),VertexRenderingFunction->({Sphere[#,.25]}&)]

This plots a graph with edges displayed as springs and vertices as spheres:

Spring[{x0_,y0_},n_:10]:=Module[{x=x0+(y0-x0)*0.05,y=y0+(x0-y0)*0.1,theta,t},theta=If[(y0-x0)[[1]]==0.,Pi/2.,ArcTan[(y0-x0)[[2]]/((y0-x0)[[1]])]];
Line[Join[{x0},Table[x+(y-x)*t+0.05 {Cos[ 2 Pi n t+theta],Sin[2  Pi n t+theta],0},{t,0,1,.005}],{y0}]]];
GraphPlot3D[{1->2,2->3,3->1,1->4,2->4,3->4},EdgeRenderingFunction-> ({Blue,Spring[#1]}&),VertexRenderingFunction-> (Sphere[#1,0.1]&)]

This plots the benzene molecule:

normal[{x_,y_}]:=0.03*{-y,x}/Norm[{x,y}];
GraphPlot[{1->2,2->3,3->4,4->5,5->6,6->1,1->2,3->4,5->6,1->7,2->8,3->9,4->10,5->11,6->12},VertexRenderingFunction->(Text[Style[If[#2≤6,"C","H"],Bold],#1,Background->White]&),EdgeRenderingFunction->(If[Length[#1]>2,norm=normal[First[#1]-Last[#1]];{Line[{First[#1]+norm,Last[#1]+norm}],Line[{First[#1]-norm,Last[#1]-norm}]},Line[#1]]&)]

Draw text along the edges:

GraphPlot[{1->2,2->3,3->4,4->5,5->6,6->1},EdgeRenderingFunction->({Arrow[#],Inset["Mathematica",Mean[#1],Automatic,Automatic,#[[1]]-#[[2]],Background->White]}&)]

Draw graphics on each edge:

arrow=;

GraphPlot[{1->5,1->6,2->4,2->6,3->4,3->5,3->6,4->6,5->6},EdgeRenderingFunction->({Line[#],Inset[arrow,Mean[#1],Automatic,Automatic,#[[1]]-#[[2]],Background->White]}&)]

Method

Algorithms to be used in (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]) can be specified using the (RefLink[Method, paclet:ref/Method]) option, either as (RefLink[Method, paclet:ref/Method])->"name" or (RefLink[Method, paclet:ref/Method])->{"name",(Subscript[opt, 1])->(Subscript[val, 1]),…}, where (Subscript[opt, i])-> (Subscript[val, i]) are method-specific options, described in separate sections. (RefLink[Method, paclet:ref/Method])->(RefLink[Automatic, paclet:ref/Automatic]) uses the "RadialDrawing" method for trees and "SpringElectricalEmbedding" otherwise.

Valid values of the (RefLink[Method, paclet:ref/Method]) option.

This draws the Petersen graph using the default method:

GraphPlot[{1->3, 1->4,2->4,2->5,3->5,6->7,7->8,8->9,9->10,6->10,1->6,2->7,3->8,4->9,5->10},VertexLabeling->True]

This draws the graph using the "SpringEmbedding" algorithm:

GraphPlot[{1->3,1->4,2->4,2->5,3->5,6->7,7->8,8->9,9->10,6->10,1->6,2->7,3->8,4->9,5->10},Method-> "SpringEmbedding",VertexLabeling->True]

This draws the graph using the "HighDimensionalEmbedding" algorithm:

GraphPlot[{1->3,1->4,2->4,2->5,3->5,6->7,7->8,8->9,9->10,6->10,1->6,2->7,3->8,4->9,5->10},Method-> "HighDimensionalEmbedding",VertexLabeling->True]

This draws the complete graph of 30 vertices using the "CircularEmbedding" method:

GraphPlot[Table[1,{30},{30}],Method-> "CircularEmbedding",VertexLabeling->True]

This draws the complete graph of 30 vertices using the "SpiralEmbedding" method in 3D:

GraphPlot3D[Table[1,{30},{30}],Method-> "SpiralEmbedding",VertexLabeling->True]

This draws the complete graph using the "RandomEmbedding" method:

GraphPlot[Table[1,{30},{30}],Method-> "RandomEmbedding",VertexLabeling->True]

This draws a graph specified in the Combinatorica Package format using coordinates that come with it:

Needs["Combinatorica`"]

GraphPlot[PetersenGraph,Method->None]

MultiedgeStyle

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

By default, multiple edges are shown if a graph is given as a list of rules:

GraphPlot[{1->2,2->1,1->2,1->2,2->3,3->4,4->5,5-> 6,6->1},DirectedEdges->True,VertexLabeling->True]

But multiple edges are not shown for graphs specified by an adjacency matrix:

GraphPlot[(({{0, 3, 0, 0, 0, 0}, {1, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0}})),VertexLabeling->True]

This spreads multiple edges by the specified amount:

GraphPlot[{1->2,2->1,1->2,1->2,2->3,3->4,4->5,5-> 6,6->1},MultiedgeStyle->1,DirectedEdges->True,VertexLabeling->True]

PackingMethod

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

This shows the packing of disconnected components by the default method:

g = Flatten[Table[x = RandomReal[1, {50 + 1}];Table[x[[i + 1]] -> x[[Mod[i^2, 50] + 1]], {i, 0, 50}], {10}]];

GraphPlot[g]

This shows the packing of disconnected components using the "ClosestPackingCenter" method:

g = Flatten[Table[x = RandomReal[1, {50 + 1}];Table[x[[i + 1]] -> x[[Mod[i^2, 50] + 1]], {i, 0, 50}], {10}]];

GraphPlot[g,PackingMethod->"ClosestPackingCenter"]

Users can adjust the packing by suboptions of (RefLink[PackingMethod, paclet:ref/PackingMethod]). The suboption "Padding" specifies the amount of space to allow between components; possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default), or a non-negative number. The suboption "PaddingFunction", which overrides "Padding", also specifies the amount of space to allow between components. It takes a list of the form {{(Subscript[w, 1]), (Subscript[h, 1])},…}, which are the width and height of the bounding box of the components, and returns a non-negative number. Options (RefLink[PackingMethod, paclet:ref/PackingMethod])->"ClosestPacking" and (RefLink[PackingMethod, paclet:ref/PackingMethod])->"ClosestPackingCenter" also accept a "PolyominoNumber" suboption, which specifies the average number of polyominoes used to approximate each disconnected component. Possible values for the "PolyominoNumber" suboption are (RefLink[Automatic, paclet:ref/Automatic]) (the default, which usually sets "PolyominoNumber" to 100), or a positive integer. A smaller "PolyominoNumber" typically has the effect of not allowing smaller components to embed in between large components.

This specifies a space of one polyomino between components:

g = Flatten[Table[x = RandomReal[1, {50 + 1}];Table[x[[i + 1]] -> x[[Mod[i^2, 50] + 1]], {i, 0, 50}], {10}]];

GraphPlot[g,PackingMethod->{"ClosestPackingCenter","Padding"->1}]

This specifies that an average of five polyominoes be used to approximate each component:

g = Flatten[Table[x = RandomReal[1, {50 + 1}];Table[x[[i + 1]] -> x[[Mod[i^2, 50] + 1]], {i, 0, 50}], {10}]];

GraphPlot[g,PackingMethod->{"ClosestPackingCenter","PolyominoNumber"->5,"Padding"->1}]

PlotRangePadding

(RefLink[PlotRangePadding, paclet:ref/PlotRangePadding]) is a common option for graphics functions inherited by (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]).

PlotStyle

(RefLink[PlotStyle, paclet:ref/PlotStyle]) is a common option for graphics functions inherited by (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]). The option (RefLink[PlotStyle, paclet:ref/PlotStyle]) specifies the style in which objects are drawn.

Draw edges with thicker lines, and both edges and vertex labels in red:

GraphPlot[{1->2,2->3,3->4,4->1,6->5,7->5,5->4,9->8,10->8,8->3,12->11,13->11,11->1,15->14,16->14,14->2},VertexLabeling->True,PlotStyle->{Red,Thickness[0.02]}]

SelfLoopStyle

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

By default, self-loops are displayed for a graph specified by a list of rules:

GraphPlot[{3->2,4->1,4->3,5->1,5->2,6->1,6->2,6->3,6->4,6->5,1->1,1->1},VertexLabeling->True]

Self-loops are not shown if the graph is specified by an adjacency matrix:

GraphPlot[(({{0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {1, 0, 0, 1, 0, 0}, {0, 0, 0, 2, 0, 0}, {0, 1, 0, 1, 0, 0}, {1, 1, 1, 1, 1, 0}})),VertexLabeling->True]

This shows self-loops with the diameter as big as the average length of the edges:

GraphPlot[{3->2,4->1,4->3,5->1,5->2,6->1,6->2,6->3,6->4,6->5,1->1,1->1},VertexLabeling->True,SelfLoopStyle->1]

VertexCoordinateRules

The option (RefLink[VertexCoordinateRules, paclet:ref/VertexCoordinateRules]) specifies the coordinates of the vertices. Possible values are (RefLink[None, paclet:ref/None]), a list of coordinates, or a list of rules specifying the coordinates of selected or all vertices.

This draws the Petersen graph using known coordinates:

GraphPlot[{1->3,1->4,2->4,2->5,3->5,6->7,7->8,8->9,9->10,6->10,1->6,2->7,3->8,4->9,5->10},VertexCoordinateRules->{{0.309,0.951},{-0.809,-0.587},{0.309,-0.951},{-0.809,0.587},{1.`,0},{0.618,1.902},{-1.618,1.175},{-1.618,-1.175},{0.618,-1.902},{2.`,0}}]

This computes vertex coordinates of the same graph using the "SpringEmbedding" algorithm:

GraphPlot[{1->3,1->4,2->4,2->5,3->5,6->7,7->8,8->9,9->10,6->10,1->6,2->7,3->8,4->9,5->10},Method->"SpringEmbedding"]

This specifies coordinates for two vertices:

GraphPlot[{1->2,2->3,3->4,4->1},VertexCoordinateRules->{1->{1,1},2->{2,3}},Frame->True,FrameTicks->True,VertexLabeling->True]

This specifies only y coordinates:

GraphPlot[{1->4,2->3,2->5,1->3},VertexCoordinateRules->{1->{Automatic,1},2->{Automatic,1},3->{Automatic,2},4->{Automatic,2},5->{Automatic,2}},Frame->True,FrameTicks->True,VertexLabeling->True]

This draws a bipartite graph by fixing x coordinates. "Anchors" are added to connect disconnected components:

bipartite={1->b,2->a,3->a,3->d,4->c,4->a,4->b};
g=Join[bipartite,Map[(Left->#[[1]])&,bipartite],Map[(Right->#[[2]])&,bipartite]];

GraphPlot[g,VertexCoordinateRules->{left->{-2,0},right->{2,0},Sequence@@Flatten[Map[({#[[1]]->{-1,Automatic},#[[2]]->{1,Automatic}})&,bipartite]]},VertexLabeling->True,VertexRenderingFunction->(If[#2=!=Left&&#2=!=Right,Text[#2,#1,Background->White],{}]&),EdgeRenderingFunction->(If[!MemberQ[{Left,Right},#2[[1]]]&&!MemberQ[{Left,Right},#2[[2]]],Line[#1],{}]&)]

When the bipartite graph is connected, it works even better without augmenting it with "Left" and "Right" anchors:

GraphPlot[bipartite,VertexCoordinateRules->Flatten[Map[({#[[1]]->{-1,Automatic},#[[2]]->{1,Automatic}})&,bipartite]],VertexLabeling->True]

VertexLabeling

The option (RefLink[VertexLabeling, paclet:ref/VertexLabeling]) specifies whether to show vertex names as labels. Possible values for this option are (RefLink[True, paclet:ref/True]), (RefLink[False, paclet:ref/False]), (RefLink[Automatic, paclet:ref/Automatic]) (the default), and (RefLink[Tooltip, paclet:ref/Tooltip]). (RefLink[VertexLabeling, paclet:ref/VertexLabeling])->True shows the labels. For graphs specified by an adjacency matrix, vertex labels are taken to be successive integers 1, 2, …, n, where n is the size of the matrix. For graphs specified by a list of rules, labels are the expressions used in the rules. (RefLink[VertexLabeling, paclet:ref/VertexLabeling])->(RefLink[False, paclet:ref/False]) displays each vertex as a point. (RefLink[VertexLabeling, paclet:ref/VertexLabeling])->(RefLink[Tooltip, paclet:ref/Tooltip]) displays each vertex as a point, but gives its name in a tooltip. (RefLink[VertexLabeling, paclet:ref/VertexLabeling])->(RefLink[Automatic, paclet:ref/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 (RefLink[Tooltip, paclet:ref/Tooltip])[(Subscript[v, k]),(Subscript[v, lbl])] anywhere in the list of rules to specify an alternative tooltip for a vertex (Subscript[v, k]).

This draws the graph with labels given as indices of the adjacency matrix:

GraphPlot[(({{0, 1, 0, 0, 0}, {0, 0, 0, 0, 0}, {1, 1, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 1, 0, 0, 0}})),VertexLabeling->True]

This uses the labels specified in the list of rules:

GraphPlot[{"A"->"B","A"->"a","B"->"C","C"->"A"},VertexLabeling->True]

This specifies alternative labels for vertices 3 and 5. Place the cursor above the vertices to see the labels:

GraphPlot[{5->4,6->2,6->Tooltip[3,"number 3"],6->5,7->1,7->3,7->4,7->6},VertexLabeling->True]

This plots vertices as points, and displays vertex names in tooltips. Place the cursor above the vertices to see the labels:

GraphPlot[{5->4,6->2,6->3,6->5,7->1,7->3,7->4,7->6},VertexLabeling->Tooltip]

VertexRenderingFunction

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

By default, vertices are displayed as points and, for small graphs, labeled in tooltips. Point the cursor at a vertex to see the tooltip:

GraphPlot[{5->3,5->4,6->2,6->4,7->1,7->4,7->5,7->6}]

This draws no vertices at all:

GraphPlot[{5->3,5->4,6->2,6->4,7->1,7->4,7->5,7->6},VertexRenderingFunction->None]

With (RefLink[VertexRenderingFunction, paclet:ref/VertexRenderingFunction])->g, each vertex is rendered with the graphics primitives given by g[(Subscript[r, i]),(Subscript[v, i]),…], where (Subscript[r, i]) is the coordinate of the vertex and (Subscript[v, i]) is the label of the vertex. Explicit settings for (RefLink[VertexRenderingFunction, paclet:ref/VertexRenderingFunction])->g override settings for (RefLink[VertexLabeling, paclet:ref/VertexLabeling]).

This shows vertices as yellow disks:

GraphPlot[{1->2,2->3,3->4,4->5,5->6,6->7,7->8,8->1,1->9,2->9,3->10,4->10,6->11,5->11,7->12,8->12},VertexRenderingFunction->({EdgeForm[Black],Yellow,Disk[#1,0.2],Black,Text[#2,#1]}&)]

This renders vertices using a predefined graphic:

gr = ;

GraphPlot[{4->2,4->3,5->1,5->3,6->1,6->2,6->4,6->5},VertexRenderingFunction-> (Inset[gr,#1]&)]

A Common Suboption of All Methods

All graph drawing methods accept the method suboption "Rotation", which specifies the desired amount of clockwise rotation in radians from the default orientation. The option takes any numeric values, or (RefLink[False, paclet:ref/False]). The default is 0.

For (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]), the default orientation is derived by an alignment step where the principal axis is found and the graph drawing is aligned with the x coordinate. However if "Rotation"->(RefLink[False, paclet:ref/False]) is specified, this step is skipped.

A common suboption for all methods.

This rotates a plot of a graph by π/2, 0, and -π/2 clockwise:

GraphicsRow[Table[GraphPlot[{4->3,5->3,5->4,6->3,6->4,6->5,7->1,7->2,7->3,7->4,7->5,7->6},Method->{"Automatic","Rotation"->rot}],{rot,{-Pi/2,0,Pi/2}}]]

This shows the evolution of a graph layout process:

Grid[Partition[Table[GraphPlot[{4->3,5->3,5->4,6->3,6->4,6->5,7->1,7->2,7->3,7->4,7->5,7->6},Method->{"SpringElectricalEmbedding","Rotation"->False,"RecursionMethod"->None,MaxIterations->i},ImageSize->50],{i,15}],{5}]]

Common Suboptions of the "SpringEmbedding" and "SpringElectricalEmbedding" Methods

Both the SpringEmbedding and SpringElectricalEmbedding methods belong to the family of so-called force-directed methods. These methods work by calculating the force on each vertex, and iteratively moving the vertex along the force in an effort to minimize the overall system's energy. See [8] for algorithmic details. These two methods have the following common options.

Common suboptions for "SpringEmbedding" and "SpringElectricalEmbedding" methods.

"EnergyControl"

The suboption "EnergyControl" specifies limitations on the total energy of the system during minimization. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default), "Monotonic", or "NonMonotonic". When the value is "Monotonic", a step along the force will only be accepted if the energy is lowered. When the value is "NonMonotonic", a step along the force will be accepted even if the energy is not lowered.

"InferentialDistance"

The suboption "InferentialDistance" specifies a cutoff distance beyond which the interaction between vertices is assumed to be nonexistent. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default) or a positive numeric value. For the "SpringEmbedding" method, if the graph distance between a vertex i and a vertex j is greater than the option value of "InferentialDistance", the repulsive and attractive spring force between i and j is ignored. For the "SpringElectricalEmbedding" method, if the Euclidean distance between a vertex i and a vertex j is greater than the option value of "InferentialDistance", the repulsive force between i and j is ignored.

This draws a random tree using the "SpringElectricalEmbedding" method:

g=RandomInteger[#]->#+1&/@Range[0,1000];

GraphPlot[g,Method->"SpringElectricalEmbedding"]

Using a smaller (more negative) "RepulsiveForcePower" option value (see the next section), the graph now fills more space:

GraphPlot[g,Method->{"SpringElectricalEmbedding","RepulsiveForcePower"->-2}]

A similar effect can be achieved using a small "InferentialDistance" option value:

GraphPlot[g,Method->{"SpringElectricalEmbedding","InferentialDistance"->.5}]

MaxIterations

The option (RefLink[MaxIterations, paclet:ref/MaxIterations]) specifies the maximum number of iterations to be used in attempting to minimize the energy. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default) or a positive integer.

"RandomSeed"

The option "RandomSeed" specifies a seed for the random number generator that computes the initial vertex placement. Changing this option usually affects the orientation of the drawing of the graph, but it can also change the layout. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) or an integer.

This shows the effect of different random seed values on drawing the Petersen graph:

g={1->3,1->4,2->4,2->5,3->5,6->7,7->8,8->9,9->10,6->10,1->6,2->7,3->8,4->9,5->10};

GraphPlot[g,Method->{"SpringElectricalEmbedding","RandomSeed"->Automatic},VertexLabeling->True]

GraphPlot[g,Method->{"SpringElectricalEmbedding","RandomSeed"->4321},VertexLabeling->True]

"RecursionMethod"

The option "RecursionMethod" specifies whether the graph layout should be produced by a recursive procedure. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default), "Multilevel", or (RefLink[None, paclet:ref/None]). In a "Multilevel" algorithm, the graph is successively coarsened into graphs with a smaller and smaller number of vertices. The coarser graphs are laid out first, and those layouts are interpolated into the finer graphs and then further refined.

Suboptions for "Multilevel".

For the option "Randomize", possible values are (RefLink[Automatic, paclet:ref/Automatic]), (RefLink[True, paclet:ref/True]), and (RefLink[False, paclet:ref/False]). For "MinSize", possible values are (RefLink[Automatic, paclet:ref/Automatic]) or a positive number. For "CoarseningScheme", the implemented algorithms are based on either a maximal independent vertex set, which forms the coarse vertices, or a maximal independent edge set, also called a matching. In a matching, two vertices that form an edge are merged to form a coarse graph vertex. The following are possible values for "CoarseningScheme".

"StepControl"

The option "StepControl" defines how step length is modified during energy minimization. It can be (RefLink[Automatic, paclet:ref/Automatic]) (the default), "Monotonic" (where step length can only be decreased), "NonMonotonic" (where step length can be made larger or smaller), or "StrictlyMonotonic" (where step length is strictly reduced between iterations).

"StepLength"

The option "StepLength" gives the initial step length used in moving the vertices around. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default) or a positive real number.

Tolerance

The option (RefLink[Tolerance, paclet:ref/Tolerance]) specifies the tolerance used in terminating the energy minimization process. If the average change of coordinates of each vertex is less than the tolerance, the energy minimization process is terminated and the current coordinates are given as output. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) or a positive real number.

Method Suboptions of the "SpringElectricalEmbedding" Method

Method options for "SpringElectricalEmbedding".

"Octree"

The "Octree" option specifies whether to use an octree data structure (in three dimensions) or a quadtree data structure (in two dimensions) in the calculation of repulsive force. Possible values are (RefLink[Automatic, paclet:ref/Automatic]) (the default), (RefLink[True, paclet:ref/True]), or (RefLink[False, paclet:ref/False]). Use of an octree/quadtree data structure minimizes the complexity of computation by approximating the long-range repulsive force. However, it introduces an approximation to the force calculation. Therefore, in a few cases the result may not be as good.

"RepulsiveForcePower"

Possible values are negative real numbers, with -1 as the default. In the spring-electrical embedding, the repulsive force between two vertices i and j is (K^2)/(Subscript[d, ij]) by default. If the value of RepulsiveForcePower is r (with r<0), then the repulsive force is defined as (K^(1-r))((Subscript[d, ij])^r), where (Subscript[d, ij]) is the distance between the vertices and K is a constant coefficient.

A strong long-range repulsive force over long distance often has the boundary effect that vertices in the periphery are closer to each other than those in the center are. Specifying a weaker long-range repulsive force can sometimes alleviate this effect. This option can also be useful in drawing a graph so that it fills up more space. (See the "InferentialDistance" method option for details.)

With a repulsive force power of -2, the boundary vertices are not as close to each other as they are with the default value of -1:

GraphPlot[GridGraph[{20,20}],Method->"SpringElectricalEmbedding"]

GraphPlot[GridGraph[{20,20}],Method->{"SpringElectricalEmbedding","RepulsiveForcePower"->-2}]

Method Suboption of "HighDimensionalEmbedding"

Method option for "HighDimensionalEmbedding".

"RefinementMethod"

The option "RefinementMethod" specifies whether the result should be further refined, and which method should be used to refine it. Possible values are (RefLink[None, paclet:ref/None]) (the default), "SpringEmbedding", or "SpringElectricalEmbedding".

This shows a case where the "HighDimensionalEmbedding" method placed vertices 5 and 6 at the same position. Specifying a "RefinementMethod" option helps to draw the graph better:

g={1->2,2->3,3->4,4->1,1->5,1->6,1->7,4->7};

GraphPlot[g,Method->"HighDimensionalEmbedding",VertexLabeling->True]

GraphPlot[g,Method->{"HighDimensionalEmbedding","RefinementMethod"->"SpringElectricalEmbedding"},VertexLabeling->True]

Advanced Topics

Drawing a Graph to Fill Up More Space

While the default setting for (RefLink[GraphPlot, paclet:ref/GraphPlot]) works well in general, for graphs that have a wide range of values for the vertex degree, it is often necessary to use a setting that helps the vertices to occupy less space.

The default method usually works well:

SeedRandom[321];

g=Table[i->RandomInteger[{1,52}],{i,52}]

GraphPlot[g]

However, sometimes "SpringEmbedding" produces a drawing that occupies more space:

GraphPlot[g,Method->"SpringEmbedding"]

A similar effect can be achieved with a repulsive force power smaller than the default (-1), so that the repulsive force decays more quickly over distance:

GraphPlot[g,Method->{"SpringElectricalEmbedding","RepulsiveForcePower"->-1.8}]

Alternatively, specify a cutoff distance:

GraphPlot[g,Method->{"SpringElectricalEmbedding","InferentialDistance"->4}]

For such tree-like graphs, a tree-drawing algorithm may be preferable. See "Tree Drawing" for greater control over tree layout:

GraphPlot[g,Method->"RadialDrawing"]

This draws a graph from power network modeling:

GraphPlot[ExampleData[{"Matrix","HB/1138_bus"},"Matrix"],Method->{"SpringElectricalEmbedding","InferentialDistance"->4,"RepulsiveForcePower"->-1.8},PlotRangePadding->0]

Improving Performance for Drawing Very Large Graphs

Although the default option set usually ensures a very good performance, it is often possible to further increase drawing speed and reduce memory usage by selecting specific option combinations for a particular task. For example, speed and/or memory usage can be improved using a smaller number of iterations, a smaller inferential distance, or a lower tolerance. These settings tend to reduce quality, but still frequently offer an acceptable compromise.

This is a drawing with default option settings:

g=Import["LinearAlgebraExamples/Data/nos6.mtx"];

GraphPlot[g]//Timing

A coarsening scheme based on the maximal independent vertex set is often faster and uses less memory, and yet offers a comparable layout quality:

GraphPlot[g,Method->{"SpringElectricalEmbedding","RecursionMethod"->{"Multilevel","CoarseningScheme"->"MaximalIndependentVertexSetRugeStuben"}}]//Timing

By reducing the number of iterations to 30, you can get a result still faster:

GraphPlot[g,Method->{"SpringElectricalEmbedding", MaxIterations->30}]//Timing

Setting the inferential distance to 2 and the number of iterations to 40 is also faster than the default:

GraphPlot[g,Method->{"SpringElectricalEmbedding", "InferentialDistance"->2, MaxIterations->40}]//Timing

By further reducing the number of iterations to 20, you get a result much faster:

GraphPlot[g,Method->{"SpringElectricalEmbedding", "InferentialDistance"->2, MaxIterations->20}]//Timing

A combination of the previous options is still faster:

GraphPlot[g,Method->{"SpringElectricalEmbedding", "InferentialDistance"->2, MaxIterations->20,"RecursionMethod"->{"Multilevel","CoarseningScheme"->"MaximalIndependentVertexSetRugeStuben"}}]//Timing

"HighDimensionalEmbedding" tends to be the fastest method, but the quality of the drawing often suffers:

GraphPlot[g,Method->"HighDimensionalEmbedding"]//Timing

For comparison, "SpringEmbedding" is the slowest method, but it is the only one that draws the mesh using orthogonal lines:

GraphPlot[g,Method->"SpringEmbedding"]//Timing

Extracting Vertex Coordinates from Output

In most cases, you will deal with the output of (RefLink[GraphPlot, paclet:ref/GraphPlot]) and (RefLink[GraphPlot3D, paclet:ref/GraphPlot3D]) just as with a usual (RefLink[Graphics, paclet:ref/Graphics]) expression. However, you may sometimes want to take advantage of the additional information encapsulated in the output expression, which has the form (RefLink[Graphics, paclet:ref/Graphics])[(RefLink[Annotation, paclet:ref/Annotation])[data,(RefLink[VertexCoordinateRules, paclet:ref/VertexCoordinateRules])->rules]]. Particularly, it is sometimes useful to extract coordinates of graph vertices.

Here is a simple graph:

GraphPlot[{3->2,4->1,4->3,5->1,5->2,5->4,6->1,6->2,6->3}]

This extracts the coordinates of vertices:

VertexCoordinateRules /. Cases[%, _Rule, Infinity]

Example Gallery

E. coli Transcription Networks

In a graph representation of a transcriptional regulation network that controls gene expression in cells, nodes (vertices) are operons, which are one or more genes transcribed on the same messenger ribonucleic acid (mRNA). Edges of the graph are directed from an operon that encodes a transcription factor to an operon that it directly regulates [1].

Data

This is the network [2] described as rules.

g={{"acrR"->"acrAB",2},{"ada_alkB"->"aidB",1},{"ada_alkB"->"alkA",1},{"adiA_adiY"->"adiA",1},{"alpA"->"slp",1},{"appY"->"appCBA",1},{"araC"->"araBAD",3},{"araC"->"araE",3},{"araC"->"araFG_araH_1H_2",3},{"araC"->"araJ",1},{"arcA"->"aceBAK",2},{"arcA"->"appCBA",1},{"arcA"->"appY",1},{"arcA"->"betIBA",2},{"arcA"->"cydAB",1},{"arcA"->"cyoABCDE",2},{"arcA"->"dctA",2},{"arcA"->"fadBA",2},{"arcA"->"focA_pflB",1},{"arcA"->"fumA",2},{"arcA"->"fumC",2},{"arcA"->"glcDEFGB",2},{"arcA"->"glpACB",2},{"arcA"->"gltA",2},{"arcA"->"icdA",2},{"arcA"->"lctPRD",2},{"arcA"->"mdh",2},{"arcA"->"nuoABCEFGHIJKLMN",2},{"arcA"->"sdhCDAB_b0725_sucABCD",2},{"arcA"->"sodA",2},{"argR"->"argCBH",2},{"argR"->"argD",2},{"argR"->"argE",2},{"argR"->"argF",2},{"argR"->"argI",2},{"argR"->"carAB",2},{"arsR"->"arsEFG",2},{"asnC"->"asnA",1},{"atoC"->"atoDAB",1},{"atoC"->"atoDAE",1},{"betIBA"->"betT",2},{"birA_murA"->"bioA",2},{"birA_murA"->"bioBFCD",2},{"cadC"->"cadBA",1},{"caiF"->"caiTABCDE",1},{"caiF"->"fixABCX",1},{"cbl"->"ssuEADCB",1},{"cbl"->"tauABCD",1},{"cpxAR"->"cpxP",1},{"cpxAR"->"dsbA",1},{"cpxAR"->"ecfI",1},{"cpxAR"->"htrA",1},{"cpxAR"->"motABcheAW",2},{"cpxAR"->"rotA",1},{"cpxAR"->"skp_lpxDA_fabZ",1},{"cpxAR"->"tsr",2},{"cpxAR"->"xprB_dsbC_recJ",1},{"crp"->"acs",1},{"crp"->"aldB",1},{"crp"->"ansB",1},{"crp"->"araBAD",1},{"crp"->"araC",1},{"crp"->"araE",1},{"crp"->"araFG_araH_1H_2",1},{"crp"->"araJ",1},{"crp"->"caiF",1},{"crp"->"caiTABCDE",1},{"crp"->"cirA",1},{"crp"->"cpdB",1},{"crp"->"cyaA",2},{"crp"->"dadAX",1},{"crp"->"dctA",2},{"crp"->"dcuB_fumB",2},{"crp"->"deoCABD",3},{"crp"->"dsdXA",1},{"crp"->"ebgAC",1},{"crp"->"epd_pgk",1},{"crp"->"fadL",2},{"crp"->"fixABCX",1},{"crp"->"flhDC",1},{"crp"->"focA_pflB",1},{"crp"->"fucAO",1},{"crp"->"fucPIKUR",1},{"crp"->"fur",1},{"crp"->"galETKM",3},{"crp"->"galS",1},{"crp"->"glgCAP",1},{"crp"->"glgS",1},{"crp"->"glnALG",1},{"crp"->"glpACB",1},{"crp"->"glpD",1},{"crp"->"glpFK",1},{"crp"->"glpTQ",1},{"crp"->"gltA",1},{"crp"->"gntKU",1},{"crp"->"gntT",1},{"crp"->"ivbL_ilvBN",1},{"crp"->"lacZYA",1},{"crp"->"malEFG",1},{"crp"->"malI",2},{"crp"->"malK_lamB_malM",1},{"crp"->"malS",1},{"crp"->"malT",1},{"crp"->"malXY",3},{"crp"->"manXYZ",1},{"crp"->"melAB",1},{"crp"->"melR",1},{"crp"->"mglBAC",1},{"crp"->"nagBACD",1},{"crp"->"nagE",1},{"crp"->"nupG",3},{"crp"->"ompA",2},{"crp"->"ppiA",3},{"crp"->"proP",3},{"crp"->"ptsHI_crr",3},{"crp"->"rhaBAD",3},{"crp"->"rhaT",1},{"crp"->"rpoH",3},{"crp"->"sdhCDAB_b0725_sucABCD",1},{"crp"->"speC",2},{"crp"->"srlAEBD_gutM_srlR_gutQ",1},{"crp"->"tdcABCDEFG",1},{"crp"->"tnaLAB",1},{"crp"->"tsx",3},{"crp"->"ubiG",1},{"crp"->"udp",1},{"crp"->"uhpT",1},{"crp"->"yhfA",3},{"crp"->"yiaKLMNOPQRS",1},{"csgDEFG"->"csgBA",1},{"cspA"->"gyrA",1},{"cspA"->"hns",1},{"cynR"->"cynTSX",1},{"cysB"->"cysDNC",1},{"cysB"->"cysJIH",1},{"cysB"->"cysK",1},{"cysB"->"cysPUWAM",1},{"cysB"->"tauABCD",1},{"cytR"->"deoCABD",2},{"cytR"->"nupC",2},{"cytR"->"nupG",2},{"cytR"->"ppiA",2},{"cytR"->"rpoH",2},{"cytR"->"tsx",3},{"cytR"->"udp",2},{"deoR"->"deoCABD",2},{"deoR"->"nupG",2},{"deoR"->"tsx",2},{"dnaA"->"nrdAB",1},{"dnaA"->"rpoH",2},{"dsdC"->"dsdXA",1},{"ebgR"->"ebgAC",2},{"envY_ompT"->"ompC",1},{"envY_ompT"->"ompF",1},{"evgA"->"ompC",1},{"exuR"->"exuT",2},{"exuR"->"uxaCA",2},{"exuR"->"uxuABR",2},{"fadR"->"fabA",1},{"fadR"->"fadBA",2},{"fadR"->"fadL",2},{"fadR"->"iclMR",2},{"fadR"->"uspA",2},{"fecIR"->"fecABCDE",1},{"fhlA"->"fdhF",1},{"fhlA"->"hycABCDEFGH",1},{"fhlA"->"hypABCDE",1},{"flhDC"->"flgAMN",1},{"flhDC"->"flgBCDEFGHIJK",1},{"flhDC"->"flhBAE",1},{"flhDC"->"fliAZY",1},{"flhDC"->"fliE",1},{"flhDC"->"fliFGHIJK",1},{"flhDC"->"fliLMNOPQR",1},{"fliAZY"->"flgBCDEFGHIJK",1},{"fliAZY"->"flgKL",1},{"fliAZY"->"flgMN",1},{"fliAZY"->"flhBAE",1},{"fliAZY"->"fliC",1},{"fliAZY"->"fliDST",1},{"fliAZY"->"fliE",1},{"fliAZY"->"fliFGHIJK",1},{"fliAZY"->"fliLMNOPQR",1},{"fliAZY"->"motABcheAW",1},{"fliAZY"->"tarTapcheRBYZ",1},{"fliAZY"->"tsr",1},{"fnr"->"acs",1},{"fnr"->"ansB",1},{"fnr"->"arcA",1},{"fnr"->"aspA",1},{"fnr"->"caiF",1},{"fnr"->"cydAB",2},{"fnr"->"cyoABCDE",2},{"fnr"->"dcuB_fumB",1},{"fnr"->"dmsABC",1},{"fnr"->"fdnGHI",1},{"fnr"->"focA_pflB",1},{"fnr"->"frdABCD",1},{"fnr"->"glpACB",1},{"fnr"->"hypABCDE",1},{"fnr"->"icdA",2},{"fnr"->"narGHJI",1},{"fnr"->"narK",1},{"fnr"->"ndh",2},{"fnr"->"nirBDC_cysG",1},{"fnr"->"nuoABCEFGHIJKLMN",2},{"fnr"->"sdhCDAB_b0725_sucABCD",2},{"fnr"->"tdcABCDEFG",1},{"FruR"->"aceBAK",2},{"FruR"->"adhE",2},{"FruR"->"fruBKA",2},{"FruR"->"icdA",1},{"FruR"->"ppsA",1},{"FruR"->"ptsHI_crr",3},{"FruR"->"pykF",2},{"fucPIKUR"->"fucAO",1},{"fur"->"cirA",2},{"fur"->"entCEBA",2},{"fur"->"fecIR",2},{"fur"->"fepA_entD",2},{"fur"->"fepB",2},{"fur"->"fepDGC",2},{"fur"->"fhuACDB",2},{"fur"->"sodA",2},{"fur"->"tonB",2},{"GalR"->"galETKM",2},{"GalR"->"galS",2},{"galS"->"mglBAC",2},{"gatR_1"->"gatYZABCDR_2",2},{"gcvA"->"gcvTHP",3},{"gcvR"->"gcvTHP",2},{"glcC"->"glcDEFGB",1},{"glnALG"->"glnHPQ",3},{"glnALG"->"nac",1},{"glpR"->"glpACB",2},{"glpR"->"glpD",2},{"glpR"->"glpFK",2},{"glpR"->"glpTQ",2},{"gntR"->"edd_eda",2},{"gntR"->"gntKU",2},{"gntR"->"gntT",2},{"hcaR"->"hcaA1A2CBD_yphA",1},{"himA"->"aceBAK",1},{"himA"->"caiTABCDE",2},{"himA"->"carAB",3},{"himA"->"dps",1},{"himA"->"ecpD_htrE",1},{"himA"->"focA_pflB",1},{"himA"->"glcDEFGB",1},{"himA"->"glnHPQ",3},{"himA"->"himD",2},{"himA"->"hycABCDEFGH",1},{"himA"->"hypABCDE",1},{"himA"->"narGHJI",1},{"himA"->"narK",1},{"himA"->"nuoABCEFGHIJKLMN",2},{"himA"->"ompC",2},{"himA"->"ompF",3},{"himA"->"ompR_envZ",2},{"himA"->"osmE",2},{"himA"->"pspABCDE",1},{"himA"->"sodA",2},{"himA"->"tdcABCDEFG",1},{"hns"->"caiF",2},{"hns"->"flhDC",1},{"hns"->"fliAZY",1},{"hns"->"nhaA",1},{"hns"->"osmC",1},{"hns"->"rcsAB",1},{"hns"->"stpA",2},{"hydHG"->"zraP",1},{"iclMR"->"aceBAK",2},{"iclMR"->"acs",2},{"ilvY"->"ilvC",1},{"kdpDE"->"kdpABC",1},{"lacI"->"lacZYA",2},{"leuO"->"leuLABCD",1},{"lexA_dinF"->"polB",2},{"lexA_dinF"->"recA",2},{"lexA_dinF"->"recN",2},{"lexA_dinF"->"rpsU_dnaG_rpoD",2},{"lexA_dinF"->"ssb",2},{"lexA_dinF"->"sulA",2},{"lexA_dinF"->"umuDC",2},{"lexA_dinF"->"uvrA",2},{"lexA_dinF"->"uvrB",2},{"lexA_dinF"->"uvrC",2},{"lexA_dinF"->"uvrD",2},{"lrp"->"gcvTHP",1},{"lrp"->"gltBDF",1},{"lrp"->"ilvIH",1},{"lrp"->"kbl_tdh",3},{"lrp"->"livJ",2},{"lrp"->"livKHMGF",2},{"lrp"->"lysU",2},{"lrp"->"ompC",2},{"lrp"->"ompF",1},{"lrp"->"oppABCDF",2},{"lrp"->"osmC",1},{"lrp"->"sdaA",2},{"lrp"->"serA",1},{"lrp"->"stpA",1},{"lysR"->"lysA",1},{"lysR"->"tdcABCDEFG",1},{"malI"->"malXY",2},{"malT"->"malEFG",1},{"malT"->"malK_lamB_malM",1},{"malT"->"malPQ",1},{"malT"->"malS",1},{"malT"->"malZ",1},{"marRAB"->"fpr",1},{"marRAB"->"fumC",1},{"marRAB"->"nfo",1},{"marRAB"->"sodA",1},{"marRAB"->"zwf",1},{"melR"->"melAB",1},{"metJ"->"metA",2},{"metJ"->"metC",2},{"metJ"->"metF",2},{"metJ"->"metR",2},{"metR"->"glyA",1},{"metR"->"metA",1},{"metR"->"metH",1},{"mhpR"->"mhpABCDFE",1},{"mlc"->"malT",2},{"mlc"->"manXYZ",2},{"mlc"->"ptsG",2},{"mlc"->"ptsHI_crr",2},{"modE"->"modABC",2},{"nac"->"gdhA",2},{"nac"->"putAP",1},{"nadR"->"nadB",2},{"nadR"->"pncB",2},{"nagBACD"->"glmUS",3},{"nagBACD"->"manXYZ",2},{"nagBACD"->"nagE",2},{"narL"->"adhE",2},{"narL"->"caiF",2},{"narL"->"dcuB_fumB",2},{"narL"->"dmsABC",2},{"narL"->"fdnGHI",1},{"narL"->"focA_pflB",2},{"narL"->"frdABCD",2},{"narL"->"narGHJI",1},{"narL"->"narK",1},{"narL"->"nirBDC_cysG",1},{"narL"->"nrfABCDEFG",1},{"narL"->"nuoABCEFGHIJKLMN",1},{"narL"->"torCAD",2},{"nhaR"->"nhaA",1},{"nlpD_rpoS"->"acs",1},{"nlpD_rpoS"->"adhE",1},{"nlpD_rpoS"->"aldB",1},{"nlpD_rpoS"->"alkA",1},{"nlpD_rpoS"->"appY",1},{"nlpD_rpoS"->"cpxAR",1},{"nlpD_rpoS"->"dps",1},{"nlpD_rpoS"->"ftsQAZ",1},{"nlpD_rpoS"->"katG",1},{"nlpD_rpoS"->"narZYWV",1},{"nlpD_rpoS"->"nhaA",1},{"nlpD_rpoS"->"osmC",1},{"nlpD_rpoS"->"osmY",1},{"nlpD_rpoS"->"proP",1},{"ompR_envZ"->"csgBA",1},{"ompR_envZ"->"csgDEFG",1},{"ompR_envZ"->"fadL",2},{"ompR_envZ"->"flhDC",2},{"ompR_envZ"->"ompC",1},{"ompR_envZ"->"ompF",3},{"oxyR"->"ahpCF",1},{"oxyR"->"dps",1},{"oxyR"->"gorA",1},{"oxyR"->"katG",1},{"phoBR"->"phnCDE_f73_phnFGHIJKLMNOP",1},{"phoBR"->"phoA",1},{"phoBR"->"phoE",1},{"phoBR"->"pstSCAB_phoU",1},{"pspF"->"pspABCDE",1},{"purR"->"codBA",2},{"purR"->"cvpA_purF_ubiX",2},{"purR"->"gcvTHP",2},{"purR"->"glnB",2},{"purR"->"glyA",2},{"purR"->"guaBA",2},{"purR"->"prsA",2},{"purR"->"purC",2},{"purR"->"purEK",2},{"purR"->"purHD",2},{"purR"->"purL",2},{"purR"->"purMN",2},{"purR"->"pyrC",2},{"purR"->"pyrD",2},{"purR"->"speA",2},{"purR"->"ycfC_purB",2},{"rbsR"->"rbsDACBK",2},{"rcsA"->"ftsQAZ",1},{"rcsA"->"wza_wzb_b2060_wcaA_wcaB",1},{"rhaSR"->"rhaBAD",1},{"rhaSR"->"rhaT",1},{"rob"->"aslB",1},{"rob"->"fumC",1},{"rob"->"galETKM",2},{"rob"->"inaA",1},{"rob"->"marRAB",1},{"rob"->"mdlA",1},{"rob"->"nfo",1},{"rob"->"sodA",1},{"rob"->"ybaO",1},{"rob"->"ybiS",1},{"rob"->"yfhD",1},{"rob"->"zwf",1},{"rpiR_alsBACEK"->"rpiB",2},{"rpoE_rseABC"->"cutC",1},{"rpoE_rseABC"->"dapA_nlpB_purA",1},{"rpoE_rseABC"->"ecfABC",1},{"rpoE_rseABC"->"ecfD",1},{"rpoE_rseABC"->"ecfF",1},{"rpoE_rseABC"->"ecfG",1},{"rpoE_rseABC"->"ecfH",1},{"rpoE_rseABC"->"ecfI",1},{"rpoE_rseABC"->"ecfJ",1},{"rpoE_rseABC"->"ecfK",1},{"rpoE_rseABC"->"ecfLM",1},{"rpoE_rseABC"->"fkpA",1},{"rpoE_rseABC"->"htrA",1},{"rpoE_rseABC"->"ksgA_epaG_epaH",1},{"rpoE_rseABC"->"lpxDA_fabZ",1},{"rpoE_rseABC"->"mdoGH",1},{"rpoE_rseABC"->"nlpB_purA",1},{"rpoE_rseABC"->"ostA_surA_pdxA",1},{"rpoE_rseABC"->"rfaDFCL",1},{"rpoE_rseABC"->"rpoD",1},{"rpoE_rseABC"->"rpoH",1},{"rpoE_rseABC"->"skp_lpxDA_fabZ",1},{"rpoE_rseABC"->"uppS_cdsA_ecfE",1},{"rpoE_rseABC"->"xprB_dsbC_recJ",1},{"rpoH"->"clpP",1},{"rpoH"->"dnaKJ",1},{"rpoH"->"grpE",1},{"rpoH"->"hflB",1},{"rpoH"->"htpG",1},{"rpoH"->"htpY",1},{"rpoH"->"ibpAB",1},{"rpoH"->"lon",1},{"rpoH"->"mopA",1},{"rpoH"->"mopB",1},{"rpoN"->"atoC",1},{"rpoN"->"dctA",1},{"rpoN"->"fdhF",1},{"rpoN"->"fhlA",1},{"rpoN"->"glnALG",1},{"rpoN"->"glnHPQ",1},{"rpoN"->"hycABCDEFGH",1},{"rpoN"->"hypA",1},{"rpoN"->"nac",1},{"rpoN"->"nycA",1},{"rpoN"->"pspABCDE",1},{"rpoN"->"rtcR",1},{"rpoN"->"zraP",1},{"rtcR"->"rtcAB",2},{"soxR"->"soxS",1},{"soxS"->"acnA",1},{"soxS"->"fpr",1},{"soxS"->"fumC",1},{"soxS"->"nfo",1},{"soxS"->"sodA",1},{"soxS"->"zwf",1},{"tdcAR"->"tdcABCDEFG",1},{"torR"->"torCAD",1},{"treR"->"treBC",2},{"trpR"->"aroH",2},{"trpR"->"aroL_yaiA_aroM",2},{"trpR"->"mtr",2},{"trpR"->"trpLEDCBA",2},{"tyrR"->"aroF_tyrA",2},{"tyrR"->"aroG",2},{"tyrR"->"aroL_yaiA_aroM",2},{"tyrR"->"aroP",2},{"tyrR"->"mtr",1},{"tyrR"->"tyrB",2},{"tyrR"->"tyrP",3},{"uhpA"->"uhpT",1},{"uidR"->"uidRABC",2},{"uxuABR"->"uidRABC",2},{"xapR"->"xapAB",1},{"xylFGHR"->"xylAB",1},{"yhdG_fis"->"adhE",1},{"yhdG_fis"->"alaWX",1},{"yhdG_fis"->"aldB",3},{"yhdG_fis"->"argU",1},{"yhdG_fis"->"argW",1},{"yhdG_fis"->"argX_hisR_leuT_proM",1},{"yhdG_fis"->"aspV",1},{"yhdG_fis"->"leuQPV",1},{"yhdG_fis"->"leuX",1},{"yhdG_fis"->"lysT_valT_lysW",1},{"yhdG_fis"->"metT_leuW_glnUW_metU_glnVX",1},{"yhdG_fis"->"metY_yhbC_nusA_infB",1},{"yhdG_fis"->"nrdAB",1},{"yhdG_fis"->"pdhR_aceEF_lpdA",1},{"yhdG_fis"->"pheU",1},{"yhdG_fis"->"pheV",1},{"yhdG_fis"->"proK",1},{"yhdG_fis"->"proL",1},{"yhdG_fis"->"proP",1},{"yhdG_fis"->"sdhCDAB_b0725_sucABCD",1},{"yhdG_fis"->"serT",1},{"yhdG_fis"->"serX",1},{"yhdG_fis"->"thrU_tyrU_glyT_thrT",1},{"yhdG_fis"->"thrW",1},{"yhdG_fis"->"tyrTV",1},{"yhdG_fis"->"valUXY_lysV",1},{"yiaJ"->"yiaKLMNOPQRS",2},{"yjbK"->"znuABC",2},{"yjdHG"->"dctA",1},{"yjdHG"->"dcuB_fumB",1},{"yjdHG"->"frdABCD",1},{"zntR"->"zntA",1}};

Drawing the Network

The network consists of many components. Mouse over vertices to see the labels:

GraphPlot[g,EdgeLabeling->Automatic,VertexLabeling->Tooltip]

Use a different component packing method:

GraphPlot[g,EdgeLabeling->Automatic,VertexLabeling->Tooltip,PackingMethod->"ClosestPackingCenter"]

This spreads out the vertices:

GraphPlot[g,Method->{"SpringElectricalEmbedding","RepulsiveForcePower"->-2},EdgeLabeling->Automatic, VertexLabeling->Tooltip,PackingMethod->"ClosestPackingCenter"]

An alternative way of spreading out the vertices:

GraphPlot[g,Method->{"SpringElectricalEmbedding","InferentialDistance"->6},EdgeLabeling->Automatic,VertexLabeling->Tooltip,PackingMethod->"ClosestPackingCenter"]

Protein: An Oxidoreductase

This plots an oxidoreductase protein [3] using the data from [4]:

GraphPlot[{{1->2,1},{1->9,2},{1->17,2},{2->3,1},{2->9,2},{3->49,2},{4->5,2},{4->42,2},{5->6,2},{5->9,2},{5->17,2},{5->42,1},{6->7,1},{6->8,2},{6->17,2},{6->28,2},{6->42,2},{7->8,2},{7->16,2},{7->28,2},{7->44,2},{8->10,2},{8->11,2},{8->14,2},{8->16,2},{8->18,2},{8->19,2},{8->28,2},{9->17,2},{10->11,1},{10->12,2},{10->13,2},{10->14,2},{10->17,2},{10->18,2},{11->12,2},{11->18,2},{12->13,2},{12->14,2},{12->18,2},{13->14,2},{13->15,2},{13->16,2},{13->18,2},{13->32,2},{14->15,1},{14->16,2},{14->18,2},{14->32,1},{14->36,2},{15->16,2},{15->32,2},{15->36,2},{15->37,2},{16->17,2},{16->18,2},{16->32,2},{16->33,2},{16->37,2},{18->19,2},{19->20,2},{19->43,2},{20->21,2},{20->43,2},{21->22,2},{22->27,2},{22->28,2},{22->29,2},{23->24,2},{23->25,2},{23->26,2},{23->27,2},{23->30,2},{23->31,2},{23->39,2},{24->25,2},{24->31,2},{24->39,2},{25->26,2},{25->31,2},{26->27,2},{26->30,2},{26->31,2},{26->32,2},{27->30,2},{28->29,2},{29->85,2},{30->31,2},{30->32,2},{30->33,2},{32->36,2},{32->85,2},{33->36,2},{35->36,2},{35->79,2},{35->82,2},{36->37,2},{37->38,2},{39->40,2},{39->41,2},{39->47,2},{40->41,2},{40->46,2},{40->48,2},{43->44,2},{44->45,1},{45->46,1},{47->48,2},{50->51,1},{50->52,2},{50->59,1},{50->67,2},{51->52,2},{51->59,2},{51->67,2},{52->53,1},{53->93,2},{53->99,2},{54->55,2},{54->92,2},{55->56,2},{55->59,2},{55->67,2},{55->92,1},{56->57,1},{56->58,2},{56->67,2},{56->78,2},{56->92,2},{57->58,2},{57->66,2},{57->78,2},{57->94,2},{58->60,2},{58->61,2},{58->64,2},{58->66,2},{58->68,2},{58->69,2},{58->78,2},{59->67,2},{60->61,2},{60->62,2},{60->64,2},{60->67,2},{60->68,2},{61->62,2},{61->68,2},{62->63,2},{62->68,2},{63->64,2},{63->65,2},{63->66,2},{63->68,2},{63->82,2},{64->65,1},{64->66,2},{64->68,2},{64->82,1},{64->86,2},{65->66,2},{65->82,2},{65->86,2},{65->87,2},{66->67,2},{66->68,2},{66->82,2},{66->83,2},{66->87,2},{68->69,2},{69->70,2},{69->93,2},{70->71,2},{71->72,2},{72->77,2},{72->78,2},{72->79,2},{73->74,2},{73->75,2},{73->76,2},{73->77,2},{73->80,2},{73->81,2},{73->89,2},{74->75,2},{74->81,2},{74->89,2},{75->76,2},{75->81,2},{76->77,2},{76->80,2},{76->81,2},{76->82,2},{77->80,2},{78->79,2},{80->81,2},{80->82,2},{80->83,2},{82->86,2},{85->86,2},{86->87,2},{87->88,2},{89->90,2},{89->91,2},{89->97,2},{90->91,2},{90->96,2},{90->98,2},{93->94,2},{94->95,1},{95->96,1},{97->98,2}},EdgeLabeling->Automatic,MultiedgeStyle->False]

Square Dielectric Waveguide

A square sparse matrix can be viewed as an adjacency matrix of a graph; therefore it is often instructive to "draw" the sparse matrix using (RefLink[GraphPlot, paclet:ref/GraphPlot]). An example is given below, and the graph drawing of over one thousand matrices can be found at [7].

This graph represents a sparse matrix used in electrical engineering [5]:

g=Import["ftp://math.nist.gov/pub/MatrixMarket2/NEP/dwave/dwa512.mtx.gz"]

GraphPlot3D[g,VertexRenderingFunction-> None]

Social Network

Graph drawing is a powerful tool in visualizing social structures.

This plots a social network:

GraphPlot[{"Li"->"Hu","Wang"->"Hu","Li"->"Wang","Carol"->"Andre","Carol"->"Fernando","Carol"->"Diane","Andre"->"Diane","Andre"->"Fernando","Andre"->"Beverly","Fernando"->"Diane","Fernando"->"Garth","Fernando"->"Heather","Diane"->"Beverly","Diane"->"Garth","Diane"->"Ed","Beverly"->"Garth","Beverly"->"Ed","Garth"->"Ed","Garth"->"Heather","Jane"->"Li","Jane"->"Hu","Heather"->"Ike","Ike"->"Jane","Li"->"Yang","Yang"->"Liu","Liu"->"Wang"},VertexLabeling->True,PlotRangePadding->Automatic]

Graphs from Words and Texts

This plots a network of words all starting with "din". Here, two nearest words are found for each word and linked to it with an edge:

words=DictionaryLookup["din*"];

nearbys=Flatten[Map[(Thread[#->DeleteCases[Nearest[words,#,3],#]])&,words]];

GraphPlot[nearbys,Method-> {"SpringElectricalEmbedding","RepulsiveForcePower"-> -3},VertexRenderingFunction->(Text[#2,#1,Background->White]&)]

This generates a graph by linking each letter in a word to all the letters that follow it in the word:

WordPlot[w_String]:=GraphPlot[(x=Characters[w];
Thread[Drop[x,-1]->Drop[x,1]]),VertexLabeling->True,DirectedEdges->True];

WordPlot["Shakespeare"]

This generates a graph by linking words in a text with subsequent words:

TextPlot[w_String]:=GraphPlot[(x=Map[ToLowerCase,StringCases[w,WordCharacter..]];
g=Thread[Drop[x,-1]->Drop[x,1]];
g),DirectedEdges->True,VertexLabeling->True];

TextPlot["to be or not to be, that is the question."]

Torus

This defines a torus and plots it in 3D:

Torus[m_, n_] := 
  SparseArray[
    Flatten[Table[{{i*n + j + 1, Mod[i + 1, m]*n + j + 1} -> 
            1, {i*n + j + 1, Mod[i - 1, m]*n + j + 1} -> 
            1, {i*n + j + 1, i*n + Mod[j + 1, n] + 1} -> 
            1, {i*n + j + 1, i*n + Mod[j - 1, n] + 1} -> 1}, {i, 0, 
          m - 1}, {j, 0, n - 1}]], {m*n, m*n}];

GraphPlot3D[Torus[40,40],VertexRenderingFunction->None]

References

[1] Milo, R., S. Shen-Orr, S. Itzkovitz, N. Kashtan, D. Chklovskii, and U. Alon. "Network Motifs: Simple Building Blocks of Complex Networks." Science 298, no. 5594 (2002): 824–827.

[2] Alon, U. "Collection of Complex Networks." Uri Alon Homepage 2007.

[3] Milo, R., S. Itzkovitz, N. Kashtan, et al. "Superfamilies of Designed and Evolved Networks." Science 303, no. 5663 (2004): 1538–1542.

[4] Alon, U. "1AORInter." network Motifs 2007.

[5] National Institute of Standards and Technology. "DWA512: Square Dielectric Waveguide." Matrix Market 2007. (WebLink[http://math.nist.gov/MatrixMarket/data/NEP/dwave/dwa512.html, http://math.nist.gov/MatrixMarket/data/NEP/dwave/dwa512.html])

[6] Freivalds, K., U. Dogrusoz, and P. Kikusts, "Disconnected Graph Layout and the Polyomino Packing Approach." Lecture Notes in Computer Science: Revised Papers from the 9th International Symposium on Graph Drawing 2265 (2001): 378–391.

[7] Hu, Y. F. "Graph Drawing of Square Matrices from University of Florida Sparse Matrix Collection." (2007).

[8] Hu, Y. F. "Efficient, High-Quality Force-Directed Graph Drawing." The Mathematica Journal 10, no. 1 (2006): 37–71.