({{, (RefLink[GraphLayout, paclet:ref/GraphLayout]) 
is an option to (RefLink[Graph, paclet:ref/Graph]) and related functions that specifies what layout to use.}})

OpenersNotesSection(Spacer1)Details

A graph layout is typically computed using several stages. With (RefLink[GraphLayout, paclet:ref/GraphLayout])->{(Subscript[s, 1])->(Subscript[m, 1]),…}, stage (Subscript[s, i]) is handled by method (Subscript[m, i]).

Possible graph layout stages are:

"VertexLayout" methods include:

Possible special embeddings include:

Possible structured embeddings for layered graphs such as trees and directed acyclic graphs include:

Possible optimizing embeddings all minimize a quantity and include:

"EdgeLayout" methods include:

"PackingLayout" methods include:

OpenersPrimaryExamplesSection(Spacer1)Examples  (105)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Graph layouts on particular curves:

Table[PathGraph[Range[20],GraphLayout->l,PlotLabel->l],{l,{"CircularEmbedding","SpiralEmbedding"}}]

Graph layouts that satisfy optimality criteria:

Table[GridGraph[{10,10},GraphLayout->l,PlotLabel->Style[l,10]],{l,{"SpringEmbedding","SpringElectricalEmbedding","HighDimensionalEmbedding"}}]

OpenersExampleSection1(Spacer1)Scope  (95)

OpenersExampleSubsection0(Spacer1)Basic Use  (3)

Change the default layout for (RefLink[Graph, paclet:ref/Graph]):

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4,4\[UndirectedEdge]5,5\[UndirectedEdge]6,6\[UndirectedEdge]7,7\[UndirectedEdge]8,8\[UndirectedEdge]9,9\[UndirectedEdge]10}]

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4,4\[UndirectedEdge]5,5\[UndirectedEdge]6,6\[UndirectedEdge]7,7\[UndirectedEdge]8,8\[UndirectedEdge]9,9\[UndirectedEdge]10},GraphLayout-> "DiscreteSpiralEmbedding"]

(RefLink[Graph3D, paclet:ref/Graph3D]):

Graph3D[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4,4\[UndirectedEdge]5,5\[UndirectedEdge]6,6\[UndirectedEdge]7,7\[UndirectedEdge]8,8\[UndirectedEdge]9,9\[UndirectedEdge]10}]

Graph3D[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4,4\[UndirectedEdge]5,5\[UndirectedEdge]6,6\[UndirectedEdge]7,7\[UndirectedEdge]8,8\[UndirectedEdge]9,9\[UndirectedEdge]10},GraphLayout-> "DiscreteSpiralEmbedding"]

(RefLink[TreeGraph, paclet:ref/TreeGraph]):

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4,4\[UndirectedEdge]5}]

TreeGraph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4,4\[UndirectedEdge]5},GraphLayout-> "CircularEmbedding"]

(RefLink[PathGraph, paclet:ref/PathGraph]):

PathGraph[Range[20]]

PathGraph[Range[20],GraphLayout-> "CircularEmbedding"]

Lay out planar graphs:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4,2\[UndirectedEdge]3,2\[UndirectedEdge]4,3\[UndirectedEdge]4},GraphLayout->"PlanarEmbedding"]

Bipartite graphs:

Graph[{1\[UndirectedEdge]4,1\[UndirectedEdge]5,1\[UndirectedEdge]6,2\[UndirectedEdge]4,2\[UndirectedEdge]5,2\[UndirectedEdge]6,3\[UndirectedEdge]4,3\[UndirectedEdge]5,3\[UndirectedEdge]6},GraphLayout-> "BipartiteEmbedding"]

Arbitrary graphs:

Graph[{1\[UndirectedEdge]3,2\[UndirectedEdge]3,2\[UndirectedEdge]4,2\[UndirectedEdge]5,3\[UndirectedEdge]4,3\[UndirectedEdge]5},GraphLayout-> "SpringEmbedding"]

Specify a layout for parametric graphs:

PetersenGraph[5,1,GraphLayout->"CircularEmbedding"]

Random graphs:

RandomGraph[{10,20},GraphLayout-> "CircularEmbedding"]

Matrix graphs:

AdjacencyGraph[{{0,1,0},{0,0,1},{1,0,0}},GraphLayout-> "CircularEmbedding"]

Arbitrary graph constructors:

LineGraph[PetersenGraph[],GraphLayout-> "CircularEmbedding"]

OpenersExampleSubsection1(Spacer1)Vertex Layout  (83)

OpenersExampleSubsubsection0(Spacer1)"BalloonEmbedding"  (7)

Place each vertex in an enclosing circle centered at its parent vertex:

Graph[Table[Floor[j/12]\[UndirectedEdge]j,{j,1, 30}],GraphLayout->"BalloonEmbedding"]

"BalloonEmbedding" works best for tree graphs:

TreeGraph[RandomInteger[{1,#}] \[UndirectedEdge] # + 1 & /@ Range[30], GraphLayout->"BalloonEmbedding"]

Use the option "EvenAngle"->True to place vertices evenly in an enclosing circle:

{KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "EvenAngle"->True}],
KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "EvenAngle"->False}]}

With the setting "OptimalOrder"->True, the vertex ordering optimizes the angular resolution and the aspect ratio:

{KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "OptimalOrder"->True}],
KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "OptimalOrder"->False}]}

Use the option "RootVertex"->v to set the root vertex:

{KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "RootVertex"->1}],
KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "RootVertex"->2}]}

Use "SectorAngles"->s to control the size of each sector:

KaryTree[48,5,GraphLayout->{"BalloonEmbedding", "SectorAngles"->{1->Pi/2}}]

The balloon layout works with arbitrary graphs:

RandomGraph[{10,15},GraphLayout-> "BalloonEmbedding"]

OpenersExampleSubsubsection1(Spacer1)"BipartiteEmbedding"  (2)

Place vertices on two vertical lines based on a bipartite partition:

Graph[Table[i\[UndirectedEdge]Mod[i+1,5],{i,8}],GraphLayout->"BipartiteEmbedding"]

"BipartiteEmbedding" works for bipartite graphs only:

CycleGraph[8, GraphLayout->"BipartiteEmbedding"]

OpenersExampleSubsubsection2(Spacer1)"CircularEmbedding"  (3)

Place vertices on a circle:

Graph[Table[i\[UndirectedEdge]Mod[i+1,3],{i,8}],GraphLayout->"CircularEmbedding"]

Use the option "Offset"->offset to specify the offset angles:

CompleteGraph[7,GraphLayout->{"CircularEmbedding", "Offset"->#}]&/@{Automatic,{30 Degree, 30 Degree},{50 Degree, 80 Degree}}

With the setting "OptimalOrder"->True, vertices are reordered so that they lie nicely on a circle:

edges=RandomSample[EdgeList[CycleGraph[20]],20];
{Graph[edges,GraphLayout->{"CircularEmbedding","OptimalOrder"->True}],
Graph[edges,GraphLayout->{"CircularEmbedding","OptimalOrder"->False}]}

OpenersExampleSubsubsection3(Spacer1)"CircularMultipartiteEmbedding"  (2)

Place vertices on polygon lines based on a vertex partition:

Graph[Flatten[Table[i\[UndirectedEdge]j,{i,4},{j,5,8}]],GraphLayout->{"CircularMultipartiteEmbedding", "VertexPartition"->{2,3,3}}]

Use "VertexPartition"->partition to specify a partition of vertices:

CompleteGraph[{3,3,2},GraphLayout->{"CircularMultipartiteEmbedding", "VertexPartition"->{3,3,2}}]

OpenersExampleSubsubsection4(Spacer1)"DiscreteSpiralEmbedding"  (3)

Place vertices on a discrete spiral:

Graph[Table[i\[UndirectedEdge]i+1,{i,11}],GraphLayout-> "DiscreteSpiralEmbedding"]

"DiscreteSpiralEmbedding" works best for path graphs:

PathGraph[Range[30],GraphLayout->"DiscreteSpiralEmbedding"]

With the setting "OptimalOrder"->True, vertices are reordered so that they lie nicely on a discrete spiral:

edges=RandomSample[EdgeList[PathGraph[Range[20]]],19];
{Graph[edges,GraphLayout->{"DiscreteSpiralEmbedding","OptimalOrder"->True}],
Graph[edges,GraphLayout->{"DiscreteSpiralEmbedding","OptimalOrder"->False}]}

OpenersExampleSubsubsection5(Spacer1)"GravityEmbedding"  (2)

Place vertices so that they minimize mechanical and electrical energy when each vertex as a mass point and each edge corresponds to a spring:

Graph[Table[Floor[j/12]\[UndirectedEdge]j,{j,1, 30}],GraphLayout->"GravityEmbedding"]

Use the option "RootVertex"->v to set the root vertex:

{KaryTree[48,5,GraphLayout->{"GravityEmbedding", "RootVertex"->1}],
KaryTree[48,5,GraphLayout->{"GravityEmbedding", "RootVertex"->2}]}

OpenersExampleSubsubsection6(Spacer1)"GridEmbedding"  (2)

Place vertices on a grid:

Graph[Table[i\[UndirectedEdge]Mod[i+3,8],{i,15}],GraphLayout->{"GridEmbedding","Dimension"->{4,4}}]

Use "Dimension"->dim to specify a dimension of a grid:

GridGraph[{12,12},GraphLayout->{"GridEmbedding","Dimension"->{12,12}}]

OpenersExampleSubsubsection7(Spacer1)"HighDimensionalEmbedding"  (3)

Place vertices in high dimension according to spring-electrical embedding and project down:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]5,1\[UndirectedEdge]9,2\[UndirectedEdge]4,2\[UndirectedEdge]6,2\[UndirectedEdge]10,3\[UndirectedEdge]4,3\[UndirectedEdge]7,3\[UndirectedEdge]11,4\[UndirectedEdge]8,4\[UndirectedEdge]12,5\[UndirectedEdge]6,5\[UndirectedEdge]7,5\[UndirectedEdge]13,6\[UndirectedEdge]8,6\[UndirectedEdge]14,7\[UndirectedEdge]8,7\[UndirectedEdge]15,8\[UndirectedEdge]16,9\[UndirectedEdge]10,9\[UndirectedEdge]11,9\[UndirectedEdge]13,10\[UndirectedEdge]12,10\[UndirectedEdge]14,11\[UndirectedEdge]12,11\[UndirectedEdge]15,12\[UndirectedEdge]16,13\[UndirectedEdge]14,13\[UndirectedEdge]15,14\[UndirectedEdge]16,15\[UndirectedEdge]16},GraphLayout->"HighDimensionalEmbedding"]

"HighDimensionalEmbedding" works best for large graphs:

GridGraph[{50,50},GraphLayout->"HighDimensionalEmbedding"]

Use "RandomSeed"->int to specify a seed for the random number generator that computes the initial vertex placement:

edge={1\[UndirectedEdge]3,1\[UndirectedEdge]5,1\[UndirectedEdge]7,2\[UndirectedEdge]3,2\[UndirectedEdge]6,2\[UndirectedEdge]7,2\[UndirectedEdge]8,3\[UndirectedEdge]4,3\[UndirectedEdge]8,4\[UndirectedEdge]6,5\[UndirectedEdge]8,7\[UndirectedEdge]8};

Graph[edge,GraphLayout->{"HighDimensionalEmbedding","RandomSeed"->#}]&/@{1,50}

OpenersExampleSubsubsection8(Spacer1)"LayeredEmbedding"  (7)

Place vertices in several layers in such a way as to minimize edges between nonadjacent layers:

Graph[Table[i\[UndirectedEdge]Mod[i+1,5],{i,12}], GraphLayout->"LayeredEmbedding"]

"LayeredEmbedding" works best for tree graphs:

TreeGraph[RandomInteger[{1,#}] \[UndirectedEdge] # + 1 & /@ Range[20], GraphLayout->"LayeredEmbedding"]

Use the option "LayerSizeFunction"->func to specify the relative height:

KaryTree[10,3,GraphLayout->{"LayeredEmbedding", LayerSizeFunction->(2&)}]

Use the option "RootVertex"->v to set the root vertex:

{KaryTree[10,3,GraphLayout->{"LayeredEmbedding", "RootVertex"->1}],
KaryTree[10,3,GraphLayout->{"LayeredEmbedding", "RootVertex"->4}]}

Use the option "LeafDistance"->d to specify the leaf distance:

{KaryTree[10,3,GraphLayout->{"LayeredEmbedding", "LeafDistance"->1}],
KaryTree[10,3,GraphLayout->{"LayeredEmbedding", "LeafDistance"->2}]}

Use the option "Orientation"->o to draw a tree with different orientations:

Table[KaryTree[6,3,GraphLayout->{"LayeredEmbedding", "Orientation"->o}],{o,{Top,Bottom,Left,Right}}]

The layered drawing works on arbitrary graphs:

RandomGraph[{20,30},GraphLayout-> "LayeredEmbedding"]

OpenersExampleSubsubsection9(Spacer1)"LayeredDigraphEmbedding"  (5)

Place vertices in a series of layers:

Graph[{1\[DirectedEdge]2,1\[DirectedEdge]3,2\[DirectedEdge]3,1\[DirectedEdge]4,2\[DirectedEdge]4,1\[DirectedEdge]5}, GraphLayout->"LayeredDigraphEmbedding"]

"LayeredDigraphEmbedding" works best for directed acyclic graphs:

TreeGraph[RandomInteger[{1,#}] \[DirectedEdge] # + 1 & /@ Range[20], GraphLayout->"LayeredDigraphEmbedding"]

Use the option "RootVertex"->v to set the root vertex:

Graph[{1\[DirectedEdge]2,1\[DirectedEdge]3,2\[DirectedEdge]3,1\[DirectedEdge]4,2\[DirectedEdge]4,1\[DirectedEdge]5},GraphLayout->{"LayeredDigraphEmbedding", "RootVertex"->#}]&/@{1,3}

Use the option "Orientation"->o to draw a tree with different orientations:

Table[Graph[{1\[DirectedEdge]2,1\[DirectedEdge]3,2\[DirectedEdge]3,1\[DirectedEdge]4,2\[DirectedEdge]4,1\[DirectedEdge]5},GraphLayout->{"LayeredDigraphEmbedding", "Orientation"->o}],{o,{Top,Bottom,Left,Right}}]

The layered digraph drawing works on arbitrary graphs:

RandomGraph[{20,35},GraphLayout-> "LayeredDigraphDrawing"]

OpenersExampleSubsubsection10(Spacer1)"LinearEmbedding"  (2)

Place vertices on a line:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]4},GraphLayout->"LinearEmbedding"]

Use the option "Method"->m to specify the algorithm:

Table[CompleteGraph[4,GraphLayout->{"LinearEmbedding", Method->m}],{m,{"Spectral","SpectralOrdering","TwoNormApproximation","TwoNormApproximationOrdering"}}]

OpenersExampleSubsubsection11(Spacer1)"MultipartiteEmbedding"  (2)

Place vertices on multiple line grids based on a vertex partition:

Graph[Flatten[Table[i\[UndirectedEdge]j,{i,3},{j,4,8}]],GraphLayout->{"MultipartiteEmbedding", "VertexPartition"->{2,1,3,2}}]

Use "VertexPartition"->partition to specify a partition of vertices:

CompleteGraph[{3,2,4},GraphLayout->{"MultipartiteEmbedding", "VertexPartition"->{3,2,4}}]

OpenersExampleSubsubsection12(Spacer1)"PlanarEmbedding"  (1)

Place vertices on a plane without an edge crossing:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4,2\[UndirectedEdge]3,2\[UndirectedEdge]4,3\[UndirectedEdge]4},GraphLayout->"PlanarEmbedding"]

OpenersExampleSubsubsection13(Spacer1)"RadialEmbedding"  (4)

Place vertices in concentric circles:

Graph[Table[Floor[j/7]\[UndirectedEdge]j,{j,1, 30}], GraphLayout->"RadialEmbedding"]

"RadialEmbedding" works best for tree graphs:

TreeGraph[RandomInteger[{1,#}] \[UndirectedEdge] # + 1 & /@ Range[30], GraphLayout->"RadialEmbedding"]

Use the option "RootVertex"->v to set the root vertex:

KaryTree[60,5,GraphLayout->{"RadialEmbedding", "RootVertex"->#}]&/@{1,2}

The radial drawing works on arbitrary graphs:

RandomGraph[{20,40},GraphLayout-> "RadialEmbedding"]

OpenersExampleSubsubsection14(Spacer1)"RandomEmbedding"  (1)

Place vertices randomly:

Graph[Table[i\[UndirectedEdge]Mod[i+1,10],{i,30}],GraphLayout->"RandomEmbedding"]

OpenersExampleSubsubsection15(Spacer1)"SpectralEmbedding"  (2)

Place vertices so the weighted sum of squares of mutual distances is minimized:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]5,1\[UndirectedEdge]9,2\[UndirectedEdge]4,2\[UndirectedEdge]6,2\[UndirectedEdge]10,3\[UndirectedEdge]4,3\[UndirectedEdge]7,3\[UndirectedEdge]11,4\[UndirectedEdge]8,4\[UndirectedEdge]12,5\[UndirectedEdge]6,5\[UndirectedEdge]7,5\[UndirectedEdge]13,6\[UndirectedEdge]8,6\[UndirectedEdge]14,7\[UndirectedEdge]8,7\[UndirectedEdge]15,8\[UndirectedEdge]16,9\[UndirectedEdge]10,9\[UndirectedEdge]11,9\[UndirectedEdge]13,10\[UndirectedEdge]12,10\[UndirectedEdge]14,11\[UndirectedEdge]12,11\[UndirectedEdge]15,12\[UndirectedEdge]16,13\[UndirectedEdge]14,13\[UndirectedEdge]15,14\[UndirectedEdge]16,15\[UndirectedEdge]16},GraphLayout->"SpectralEmbedding"]

Use the option "RelaxationFactor"->r to get the layout based on a relaxed Laplace matrix.

Table[GridGraph[{10,10}, GraphLayout->{"SpectralEmbedding", "RelaxationFactor"->i}],{i,0,1,.3}]

OpenersExampleSubsubsection16(Spacer1)"SpiralEmbedding"  (3)

Place vertices on a spiral:

Graph[Table[i\[UndirectedEdge]Mod[i+1,20,1],{i,20}],GraphLayout->"SpiralEmbedding"]

"SpiralEmbedding" works best for path graphs:

PathGraph[Range[40],GraphLayout->"SpiralEmbedding"]

With the setting "OptimalOrder"->True, vertices are reordered so that they lie on the spiral nicely:

edges=RandomSample[EdgeList[CycleGraph[20]],20];
{Graph[edges,GraphLayout->{"SpiralEmbedding","OptimalOrder"->True}],
Graph[edges,GraphLayout->{"SpiralEmbedding","OptimalOrder"->False}]}

OpenersExampleSubsubsection17(Spacer1)"SpringElectricalEmbedding"  (13)

Place vertices so that they minimize mechanical and electrical energy when each vertex has a charge and each edge corresponds to a spring:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]5,1\[UndirectedEdge]9,2\[UndirectedEdge]4,2\[UndirectedEdge]6,2\[UndirectedEdge]10,3\[UndirectedEdge]4,3\[UndirectedEdge]7,3\[UndirectedEdge]11,4\[UndirectedEdge]8,4\[UndirectedEdge]12,5\[UndirectedEdge]6,5\[UndirectedEdge]7,5\[UndirectedEdge]13,6\[UndirectedEdge]8,6\[UndirectedEdge]14,7\[UndirectedEdge]8,7\[UndirectedEdge]15,8\[UndirectedEdge]16,9\[UndirectedEdge]10,9\[UndirectedEdge]11,9\[UndirectedEdge]13,10\[UndirectedEdge]12,10\[UndirectedEdge]14,11\[UndirectedEdge]12,11\[UndirectedEdge]15,12\[UndirectedEdge]16,13\[UndirectedEdge]14,13\[UndirectedEdge]15,14\[UndirectedEdge]16,15\[UndirectedEdge]16},GraphLayout->"SpringElectricalEmbedding"]

"SpringElectricalEmbedding" works best for most graphs:

KnightTourGraph[10,10,GraphLayout->"SpringElectricalEmbedding"]

With the setting "EdgeWeighted"->(RefLink[True, paclet:ref/True]), edge weights are used:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,10];
weight=RandomInteger[{1,5},11];

Graph[edge,EdgeWeight->weight,GraphLayout->{"SpringElectricalEmbedding", "EdgeWeighted"->#}]&/@{True, False}

Use the option "EnergyControl"->e to specify limitations on the total energy of the system during minimization:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,{GraphLayout->{"SpringElectricalEmbedding", "EnergyControl"->#,"StepControl"->"Monotonic"}}]&/@{Automatic,"Monotonic","NonMonotonic"}

Use "InferentialDistance"->d to specify a cutoff distance beyond which the interaction between vertices is assumed to be nonexistent:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","InferentialDistance"->#}]&/@{Automatic, .1, .5}

Use "MaxIteration"->it to specify a maximum number of iterations to be used in attempting to minimize the energy:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","MaxIteration"->#}]&/@{Automatic, 1, 2}

Use "Multilevel"->method to specify a method used during a recursive procedure of coarsening a graph:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","Multilevel"->#}]&/@{Automatic, None, "MaximalIndependentVertexSet","MaximalIndependentVertexSetRugeStuben","MaximalIndependentVertexSetInjection","MaximalIndependentVertexSetRugeStubenInjection","MaximalIndependentEdgeSetHeavyEdge","MaximalIndependentEdgeSet","MaximalIndependentEdgeSetSmallestVertexWeight","Hybrid"}

With the setting "Octree"->(RefLink[True, paclet:ref/True]), an octree data structure (in three dimensions) or a quadtree data structure (in two dimensions) is used in the calculation of repulsive force:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","Octree"->#}]&/@{True,False}

Use "RandomSeed"->int to specify a seed for the random number generator that computes the initial vertex placement:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","RandomSeed"->#}]&/@{1,5}

Use "RepulsiveForcePower"->r to control how fast the repulsive force decays over distance:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","RepulsiveForcePower"->#}]&/@{-1,-2.5}

Use "StepControl"->method to define how step length is modified during energy minimization:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","StepControl"->#}]&/@{Automatic,"Monotonic","NonMonotonic","StrictlyMonotonic"}

Use "StepLength"->r to specify the initial step length used in moving the vertices around:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","StepLength"->#}]&/@{1,4.5}

Use "Tolerance"->r to specify the tolerance used in terminating the energy minimization process:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,20];

Graph[edge,GraphLayout->{"SpringElectricalEmbedding","Tolerance"->#}]&/@{Automatic,.5}

OpenersExampleSubsubsection18(Spacer1)"SpringEmbedding"  (11)

Place vertices so that they minimize mechanical energy when each edge corresponds to a spring:

Graph[{1\[UndirectedEdge]14,1\[UndirectedEdge]15,1\[UndirectedEdge]16,2\[UndirectedEdge]5,2\[UndirectedEdge]6,2\[UndirectedEdge]13,3\[UndirectedEdge]7,3\[UndirectedEdge]14,3\[UndirectedEdge]19,4\[UndirectedEdge]8,4\[UndirectedEdge]15,4\[UndirectedEdge]20,5\[UndirectedEdge]11,5\[UndirectedEdge]19,6\[UndirectedEdge]12,6\[UndirectedEdge]20,7\[UndirectedEdge]11,7\[UndirectedEdge]16,8\[UndirectedEdge]12,8\[UndirectedEdge]16,9\[UndirectedEdge]10,9\[UndirectedEdge]14,9\[UndirectedEdge]17,10\[UndirectedEdge]15,10\[UndirectedEdge]18,11\[UndirectedEdge]12,13\[UndirectedEdge]17,13\[UndirectedEdge]18,17\[UndirectedEdge]19,18\[UndirectedEdge]20},GraphLayout->"SpringEmbedding"]

"SpringEmbedding" works best for regular structured graphs:

Graph[GraphData[{"GeneralizedPetersen",{9,2}},"EdgeRules"],GraphLayout->"SpringEmbedding"]

With the setting "EdgeWeighted"->(RefLink[True, paclet:ref/True]), edge weights are used:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,10];
weight=RandomInteger[{1,5},11];

Graph[edge,EdgeWeight->weight,GraphLayout->{"SpringEmbedding", "EdgeWeighted"->#}]&/@{True, False}

Use the option "EnergyControl"->e to specify limitations on the total energy of the system during minimization:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,{GraphLayout->{"SpringEmbedding", "EnergyControl"->#}}]&/@{Automatic,"Monotonic","NonMonotonic"}

Use "InferentialDistance"->d to specify a cutoff distance beyond which the interaction between vertices is assumed to be nonexistent:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","InferentialDistance"->#}]&/@{Automatic, .5,2}

Use "MaxIteration"->it to specify a maximum number of iterations to be used in attempting to minimize the energy:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","MaxIteration"->#}]&/@{Automatic, 1, 2}

Use "Multilevel"->method to specify a method used during a recursive procedure of coarsening a graph:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","Multilevel"->#}]&/@{Automatic, None, "MaximalIndependentVertexSet","MaximalIndependentVertexSetRugeStuben","MaximalIndependentVertexSetInjection","MaximalIndependentVertexSetRugeStubenInjection","MaximalIndependentEdgeSetHeavyEdge","MaximalIndependentEdgeSet","MaximalIndependentEdgeSetSmallestVertexWeight","Hybrid"}

Use "RandomSeed"->int to specify a seed for the random number generator that computes the initial vertex placement:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","RandomSeed"->#}]&/@{1,5}

Use "StepControl"->method to define how step length is modified during energy minimization:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","StepControl"->#}]&/@{Automatic,"Monotonic","NonMonotonic","StrictlyMonotonic"}

Use "StepLength"->r to specify the initial step length used in moving the vertices around:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","StepLength"->#}]&/@{1,4.5}

Use "Tolerance"->r to specify the tolerance used in terminating the energy minimization process:

edge=RandomInteger[#]\[UndirectedEdge]#+1&/@Range[0,30];

Graph[edge,GraphLayout->{"SpringEmbedding","Tolerance"->#}]&/@{Automatic,.5}

OpenersExampleSubsubsection19(Spacer1)"StarEmbedding"  (4)

Place vertices on a star shape:

Graph[Table[1\[UndirectedEdge]i,{i,2,6}],GraphLayout->"StarEmbedding"]

"\"StarEmbedding"" works best for star-like graphs:

{StarGraph[12,GraphLayout->"StarEmbedding"],WheelGraph[12,GraphLayout->"StarEmbedding"]}

Use the option "Offset"->offset to specify the offset angles:

StarGraph[15,GraphLayout->{"StarEmbedding", "Offset"->#}]&/@{Automatic,{30 Degree, 30 Degree},{50 Degree, 80 Degree}}

Use the option "Center"->center to specify the center:

StarGraph[15,GraphLayout->{"StarEmbedding", "Center"->#}]&/@{Automatic,10}

OpenersExampleSubsubsection20(Spacer1)"TutteEmbedding"  (2)

Place vertices without crossing edges and minimize the sum of distances to neighbors:

Graph[{1\[UndirectedEdge]2,1\[UndirectedEdge]3,1\[UndirectedEdge]4,2\[UndirectedEdge]3,2\[UndirectedEdge]4,3\[UndirectedEdge]4},GraphLayout->"TutteEmbedding"]

"TutteEmbedding" works for 3-connected planar graphs only:

Graph[GraphData[{"JohnsonSkeleton",77},"EdgeList"],GraphLayout->"TutteEmbedding"]

OpenersExampleSubsubsection21(Spacer1)None  (2)

Print the elided form of a graph:

CompleteGraph[4,GraphLayout->None]

Useful for large graphs:

GridGraph[{10,10,10,10},GraphLayout->None]

OpenersExampleSubsection2(Spacer1)Packing Layout  (6)

OpenersExampleSubsubsection22(Spacer1)"ClosestPacking"  (1)

Approximate closest packing from the top left:

Graph[Table[i\[DirectedEdge]Mod[i^3,50],{i,1,50}], GraphLayout->{"PackingLayout"->"ClosestPacking"}]

OpenersExampleSubsubsection23(Spacer1)"ClosestPackingCenter"  (1)

Approximate closest packing from the center:

Graph[Table[i\[DirectedEdge]Mod[i^3,50],{i,1,50}], GraphLayout->{"PackingLayout"->"ClosestPackingCenter"}]

OpenersExampleSubsubsection24(Spacer1)"Layered"  (1)

Arrange in layers starting at the top left:

Graph[Table[i\[DirectedEdge]Mod[i^3,50],{i,1,50}], GraphLayout->{"PackingLayout"->"Layered"}]

OpenersExampleSubsubsection25(Spacer1)"LayeredLeft"  (1)

Arrange in layers starting at the left:

Graph[Table[i\[DirectedEdge]Mod[i^3,50],{i,1,50}], GraphLayout->{"PackingLayout"->"LayeredLeft"}]

OpenersExampleSubsubsection26(Spacer1)"LayeredTop"  (1)

Arrange in layers starting at the top:

Graph[Table[i\[DirectedEdge]Mod[i^3,50],{i,1,50}], GraphLayout->{"PackingLayout"->"LayeredTop"}]

OpenersExampleSubsubsection27(Spacer1)"NestedGrid"  (1)

Arrange on a nested grid:

Graph[Table[i\[DirectedEdge]Mod[i^3,50],{i,1,50}], GraphLayout->{"PackingLayout"->"NestedGrid"}]

OpenersExampleSubsection3(Spacer1)Rendering Order  (3)

OpenersExampleSubsubsection28(Spacer1)"VertexFirst"  (1)

Place vertices on the top of edges:

RandomGraph[{10,40},GraphLayout->{ "RenderingOrder"->"VertexFirst"},VertexSize->Large]

OpenersExampleSubsubsection29(Spacer1)"EdgeFirst"  (1)

Place edges on the top of vertices:

RandomGraph[{10,40},GraphLayout->{ "RenderingOrder"->"EdgeFirst"},VertexSize->Large]

OpenersExampleSubsubsection30(Spacer1)Ordering  (1)

Place vertices and edges by the specified order:

Map[Graph[{Style[1,Red],Style[2,Blue]},{2\[DirectedEdge]3}, VertexCoordinates->{{0,0},{.5,0},{1.5,0}},GraphLayout->{"RenderingOrder"->#}, VertexSize->1.5]&,{{1,2},{2,1}}]

OpenersExampleSection2(Spacer1)Applications  (2)

Layout of Wolfram System installation directory:

files=Flatten[Rest[NestList[Union[Flatten[Thread[#->FileNames["*",#]]&/@Last/@#]]&,{""->$InstallationDirectory},2]]];

Graph[files, GraphLayout->"BalloonEmbedding"]

Show the relationships between early versions of the Unix operating system:

systems={"5th Edition"\[DirectedEdge]"6th Edition","5th Edition"\[DirectedEdge]"PWB 1.0","6th Edition"\[DirectedEdge]"1 BSD","6th Edition"\[DirectedEdge]"Interdata","6th Edition"\[DirectedEdge]"LSX","6th Edition"\[DirectedEdge]"Mini Unix","6th Edition"\[DirectedEdge]"Wollongong","PWB 1.0"\[DirectedEdge]"PWB 1.2","PWB 1.0"\[DirectedEdge]"USG 1.0","1 BSD"\[DirectedEdge]"2 BSD","Interdata"\[DirectedEdge]"PWB 2.0","Interdata"\[DirectedEdge]"Unix/TS 3.0","Interdata"\[DirectedEdge]"7th Edition","PWB 1.2"\[DirectedEdge]"PWB 2.0","USG 1.0"\[DirectedEdge]"USG 2.0","USG 1.0"\[DirectedEdge]"CB Unix 1","7th Edition"\[DirectedEdge]"2 BSD","7th Edition"\[DirectedEdge]"32V","7th Edition"\[DirectedEdge]"Xenix","7th Edition"\[DirectedEdge]"Ultrix-11","7th Edition"\[DirectedEdge]"UniPlus+","7th Edition"\[DirectedEdge]"V7M","PWB 2.0"\[DirectedEdge]"Unix/TS 3.0","USG 2.0"\[DirectedEdge]"USG 3.0","CB Unix 1"\[DirectedEdge]"CB Unix 2","32V"\[DirectedEdge]"3 BSD","Unix/TS 1.0"\[DirectedEdge]"Unix/TS 3.0","USG 3.0"\[DirectedEdge]"Unix/TS 3.0","CB Unix 2"\[DirectedEdge]"CB Unix 3","3 BSD"\[DirectedEdge]"4 BSD","V7M"\[DirectedEdge]"Ultrix-11","Unix/TS 3.0"\[DirectedEdge]"TS 4.0","CB Unix 3"\[DirectedEdge]"Unix/TS++","CB Unix 3"\[DirectedEdge]"PDP-11 Sys V","4 BSD"\[DirectedEdge]"4.1 BSD","Unix/TS++"\[DirectedEdge]"TS 4.0","4.1 BSD"\[DirectedEdge]"8th Edition","4.1 BSD"\[DirectedEdge]"4.2 BSD","4.1 BSD"\[DirectedEdge]"2.8 BSD","2 BSD"\[DirectedEdge]"2.8 BSD","TS 4.0"\[DirectedEdge]"System V.0","4.2 BSD"\[DirectedEdge]"4.3 BSD","4.2 BSD"\[DirectedEdge]"Ultrix-32","2.8 BSD"\[DirectedEdge]"2.9 BSD","2.8 BSD"\[DirectedEdge]"Ultrix-11","System V.0"\[DirectedEdge]"System V.2","8th Edition"\[DirectedEdge]"9th Edition","System V.2"\[DirectedEdge]"System V.3"};

Automatically use the layered digraph embedding:

Graph[systems, VertexShapeFunction->"Square",VertexSize->{.5,.2}, VertexLabels->Placed["Name",Center],VertexStyle->Hue[0.125,0.7,0.9],VertexLabelStyle->Directive[FontFamily->"Arial", 8],ImageSize->480, EdgeShapeFunction->({Arrowheads[{{.02,.6}}],Arrow[#]}&)]

OpenersExampleSection3(Spacer1)Properties & Relations  (6)

(RefLink[GraphLayout, paclet:ref/GraphLayout]) can be used for general graphs:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},GraphLayout->"SpringEmbedding"],PathGraph[Range[10],GraphLayout->"SpringEmbedding"]}

Matrix graphs:

AdjacencyGraph[{{0,1,0},{0,0,1},{1,0,0}},GraphLayout->"SpringEmbedding"]

Special graphs:

{PetersenGraph[5,2,GraphLayout->"SpringEmbedding"],GridGraph[{5,5},GraphLayout->"SpringEmbedding"]}

Random graphs:

RandomGraph[UniformGraphDistribution[50,100],GraphLayout->"CircularEmbedding"]

(RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) overrides (RefLink[GraphLayout, paclet:ref/GraphLayout]) coordinates:

{Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},GraphLayout->"SpringElectricalEmbedding"],
Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1},GraphLayout->"SpringElectricalEmbedding",VertexCoordinates->Table[{i,i},{i,0,2}]]}

Use (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions]) to extract (RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) computed using a layout algorithm:

Graph[{1\[UndirectedEdge]2,2\[UndirectedEdge]3,3\[UndirectedEdge]1}]

AbsoluteOptions[%,VertexCoordinates]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Graph, paclet:ref/Graph])  ▪  (RefLink[TreeGraph, paclet:ref/TreeGraph])  ▪  (RefLink[PathGraph, paclet:ref/PathGraph])  ▪  (RefLink[VertexCoordinates, paclet:ref/VertexCoordinates])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Visualization, paclet:guide/GraphVisualization])}, {▪(RefLinkPlain[Graph Styling, Labeling, and Layout, paclet:guide/GraphStylingAndLabeling])}, {▪(RefLinkPlain[Graph Properties, paclet:guide/GraphProperties])}, {▪(RefLinkPlain[Graphs & Networks, paclet:guide/GraphsAndNetworks])}})}})