({{, (RefLink[NestGraph, paclet:ref/NestGraph])[f,expr,n]
gives the graph obtained by starting with expr and applying f successively n times.}, {, (RefLink[NestGraph, paclet:ref/NestGraph])[f,{(Subscript[expr, 1]),(Subscript[expr, 2]),…},n]
gives the graph obtained by applying f to (Subscript[expr, 1]), (Subscript[expr, 2]), ….}, {, (RefLink[NestGraph, paclet:ref/NestGraph])[f,graph,n]
gives the graph obtained by applying f to the vertices of graph and extending the graph.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[NestGraph, paclet:ref/NestGraph]) is also known as crawl graph or tree growing.

expr can be an expression or a list of expressions or graphs.

(RefLink[NestGraph, paclet:ref/NestGraph])[f,expr] is equivalent to (RefLink[NestGraph, paclet:ref/NestGraph])[f,expr,1].

(RefLink[NestGraph, paclet:ref/NestGraph])[f,expr] gives a graph with edges {expr->(Subscript[expr, 1]),…,expr->(Subscript[expr, k])}, where f[expr] evaluates to {(Subscript[expr, 1]),…,(Subscript[expr, k])}.

(RefLink[NestGraph, paclet:ref/NestGraph])[f,{(Subscript[expr, 1]),(Subscript[expr, 2]),…}] is the graph union of (RefLink[NestGraph, paclet:ref/NestGraph])[f,(Subscript[expr, 1])] and (RefLink[NestGraph, paclet:ref/NestGraph])[f,(Subscript[expr, 2])],….

(RefLink[NestGraph, paclet:ref/NestGraph])[f,graph] is the union of graph and (RefLink[NestGraph, paclet:ref/NestGraph])[f,{(Subscript[v, 1]),…}], where (Subscript[v, i]) are the vertices of graph.

(RefLink[NestGraph, paclet:ref/NestGraph])[f,graph,n] is the union of  NestGraph[f,graph,n-1] and (RefLink[NestGraph, paclet:ref/NestGraph])[f,{(Subscript[v, 1]),…}], where (Subscript[v, i]) are the vertices of  NestGraph[f,graph,n-1].

(RefLink[NestGraph, paclet:ref/NestGraph])[f,expr,n] is equivalent to (RefLink[NestGraph, paclet:ref/NestGraph])[f,graph,n], where graph is the singleton graph with only one vertex expr and no edges.

(RefLink[NestGraph, paclet:ref/NestGraph]) takes the same options as (RefLink[Graph, paclet:ref/Graph]).

The option (RefLink[DirectedEdges, paclet:ref/DirectedEdges]) can be used to control whether an undirected or directed graph is constructed.

OpenersPrimaryExamplesSection(Spacer1)Examples  (95)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Construct a graph by starting with x and applying f successively 3 times:

NestGraph[f,x,3,VertexLabels->"Name",ImagePadding-> 40]

The function to nest can be a pure function:

NestGraph[Mod[#^2+1,10]&,Range[0,9],VertexLabels->"Name"]

Generate a binary tree of nested functions:

NestGraph[{f[#],g[#]}&,x,3,VertexLabels->"Name"]

Generate a graph of neighboring countries around Switzerland:

NestGraph[#["BorderingCountries"]&,LinguisticAssistant,2,VertexLabels->"Name"]

OpenersExampleSection1(Spacer1)Scope  (3)

(RefLink[NestGraph, paclet:ref/NestGraph]) works with any function including an expression:

NestGraph[f,x,3]

A pure function:

NestGraph[Mod[#^2+1,10]&,Range[0,9],2]

(RefLink[NestGraph, paclet:ref/NestGraph]) works with any expression including integers:

NestGraph[Mod[#^2+1,10]&,{1,2,3,4,5},2]

Strings:

NestGraph[WordData[#,"Synonyms","List"] &, "tree",2]

Graphs:

NestGraph[WordData[#,"Synonyms","List"] &, ,2]

Limit the depth of the tree:

NestGraph[WordData[#,"Synonyms","List"] &,"tree", 3]

OpenersExampleSection2(Spacer1)Options  (80)

OpenersExampleSubsection0(Spacer1)DirectedEdges  (1)

By default, a directed graph is generated:

NestGraph[Mod[#^2+1,5]&,Range[0,4],2]

Use (RefLink[DirectedEdges, paclet:ref/DirectedEdges])->(RefLink[False, paclet:ref/False]) to generate an undirected graph:

NestGraph[Mod[#^2+1,5]&,Range[0,4],2,DirectedEdges->False]

OpenersExampleSubsection1(Spacer1)EdgeLabels  (7)

Label the edge 1<->2:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{1\[DirectedEdge]2->"Hello"}]

Label all edges individually:

el=EdgeList[NestGraph[Mod[#^2+1,5]&,Range[0,2],2]]

NestGraph[Mod[#^2+1,5]&,Range[0,2],EdgeLabels->Table[el[[i]]->(Subscript["e", i]),{i,Length[el]}]]

Use any expression as a label:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{0\[DirectedEdge]1->,1\[DirectedEdge]2->,2\[DirectedEdge]0-> }]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement along an edge:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{1\[DirectedEdge]2->Placed["■■■",p]},PlotLabel->p],{p,{"Start","Middle","End"}}]

Use explicit coordinates to place labels:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{1\[DirectedEdge]2->Placed["■■■",p]},PlotLabel->p,BaselinePosition->Bottom],{p,{0,1/4,1/3}}]

Vary positions within the label:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{1\[DirectedEdge]2->Placed["■■■",{1/2,p}]},PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{1\[DirectedEdge]2->Placed[{"lbl1","lbl2"},{"Start","End"}]}]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->{1\[DirectedEdge]2->Placed[{"lbl1","lbl2","lbl3"},{"Start","Middle","End"}]}]

Use automatic labeling by values through (RefLink[Tooltip, paclet:ref/Tooltip]) and (RefLink[StatusArea, paclet:ref/StatusArea]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->Placed["Name",Tooltip]]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeLabels->Placed["Name",StatusArea]]

OpenersExampleSubsection2(Spacer1)EdgeShapeFunction  (6)

Get a list of built-in settings for (RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]):

GraphElementData["Edge"]

Undirected edges including the basic line:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->"Line"]

Lines with different glyphs on the edges:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,{"BoxLine","DiamondLine","DotLine"}}]

Directed edges including solid arrows:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","FilledArrow"]}]

Line arrows:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","UnfilledArrow"]}]

Open arrows:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","CarvedArrow"]}]

Specify an edge function for an individual edge:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->{1\[DirectedEdge]2->"DotLine"}]

Combine with a different default edge function:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->{1\[DirectedEdge]2->"BoxLine","DotLine"}]

Draw edges by running a program:

ef[pts_List,e_]:=
Block[{s=0.015,g=},{Arrowheads[{{s,0.33,g},{s,0.67,g}}],Arrow[pts]}]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeShapeFunction->ef]

(RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]) can be combined with (RefLink[EdgeStyle, paclet:ref/EdgeStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeStyle->Blue,EdgeShapeFunction->(Line[#1]&)]

(RefLink[EdgeShapeFunction, paclet:ref/EdgeShapeFunction]) has higher priority than (RefLink[EdgeStyle, paclet:ref/EdgeStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeStyle->Blue,EdgeShapeFunction->({Red,Line[#1]}&)]

OpenersExampleSubsection3(Spacer1)EdgeStyle  (2)

Style all edges:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeStyle->style,PlotLabel->style],{style,{Gray,Dashed,Thick}}]

Style individual edges:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeStyle->{1\[DirectedEdge]2->Blue,0\[DirectedEdge]1->Dashed}]

OpenersExampleSubsection4(Spacer1)EdgeWeight  (2)

Specify a weight for all edges:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeWeight->RandomInteger[5,3]]

WeightedAdjacencyMatrix[%]//MatrixForm

Use any numeric expression as a weight:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,EdgeWeight->{a,b,c}]

WeightedAdjacencyMatrix[%]//MatrixForm

OpenersExampleSubsection5(Spacer1)GraphHighlight  (3)

Highlight the vertex 1:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->Tiny,GraphHighlight->{1}]

Highlight the edge 2<->3:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->Tiny,GraphHighlight->{1\[DirectedEdge]2}]

Highlight vertices and edges:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->Tiny,GraphHighlight->{1,2,0\[DirectedEdge]1,1\[DirectedEdge]2}]

OpenersExampleSubsection6(Spacer1)GraphHighlightStyle  (2)

Get a list of built-in settings for (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]):

GraphElementData["GraphHighlightStyle"]

Use built-in settings for (RefLink[GraphHighlightStyle, paclet:ref/GraphHighlightStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,GraphHighlight->{1,1\[DirectedEdge]2},VertexSize->Small,GraphHighlightStyle->#,PlotLabel->#]&/@Select[GraphElementData["GraphHighlightStyle"],#=!=Automatic&]

OpenersExampleSubsection7(Spacer1)GraphLayout  (5)

By default, the layout is chosen automatically:

NestGraph[Mod[#^2+1,5]&,Range[0,10],2,GraphLayout->Automatic]

Specify layouts on special curves:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,10],2,GraphLayout->l,PlotLabel->l],{l,{"CircularEmbedding","SpiralEmbedding"}}]

Specify layouts that satisfy optimality criteria:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,20],2,GraphLayout->l,PlotLabel->l],{l,{"SpringEmbedding","SpringElectricalEmbedding","HighDimensionalEmbedding"}}]

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

{NestGraph[Mod[#^2+1,5]&,Range[0,5],2,GraphLayout->"SpringElectricalEmbedding"],
WheelGraph[5,GraphLayout->"SpringElectricalEmbedding",VertexCoordinates->Table[{i,i},{i,0,4}]]}

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

NestGraph[Mod[#^2+1,5]&,Range[0,5],2]

AbsoluteOptions[%,VertexCoordinates]

OpenersExampleSubsection8(Spacer1)PlotTheme  (4)

OpenersExampleSubsubsection0(Spacer1)Base Themes  (2)

Use a common base theme:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,PlotTheme->"Business"]

Use a monochrome theme:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,PlotTheme->"Monochrome"]

OpenersExampleSubsubsection1(Spacer1)Feature Themes  (2)

Use a large graph theme:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,PlotTheme->"LargeGraph"]

Use a classic diagram theme:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,PlotTheme->"ClassicDiagram"]

OpenersExampleSubsection9(Spacer1)Properties  (2)

Specify a property for vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,Properties->{2->{VertexLabels-> "hello"}}]

Edges:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,Properties->{0\[DirectedEdge]1->{EdgeLabels-> "hello"}}]

OpenersExampleSubsection10(Spacer1)VertexCoordinates  (3)

By default, any vertex coordinates are computed automatically:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2]

Extract the resulting vertex coordinates using (RefLink[AbsoluteOptions, paclet:ref/AbsoluteOptions]):

AbsoluteOptions[%,VertexCoordinates]

Specify a layout function along an ellipse:

ellipseLayout[n_,{a_,b_}]:=Table[{a Cos[2Pi/n u],b Sin[2Pi/n u]},{u,1,n}]

Graphics[Point[ellipseLayout[20,{2,1}]]]

Use it to generate vertex coordinates for a graph:

NestGraph[Mod[#^2+1,5]&,Range[0,19],2,VertexCoordinates->ellipseLayout[20,{2,1}]]

(RefLink[VertexCoordinates, paclet:ref/VertexCoordinates]) has higher priority than (RefLink[GraphLayout, paclet:ref/GraphLayout]):

NestGraph[Mod[#^2+1,5]&,Range[0,3],2,VertexCoordinates->Table[{i,i},{i,4}],GraphLayout->"CircularEmbedding"]

OpenersExampleSubsection11(Spacer1)VertexLabels  (13)

Use vertex names as labels:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->"Name"]

Label individual vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->{2->"one"}]

Label all vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->Table[i->(Subscript[v, i]),{i,0,2}]]

Use any expression as a label:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->{1->,2->,0->},ImagePadding->20]

Use (RefLink[Placed, paclet:ref/Placed]) with symbolic locations to control label placement, including outside positions:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,0,2}],PlotLabel->p,ImagePadding->20],{p,{Before,After,Below,Above}}]

Symbolic outside corner positions:

pl={{Before,Below},{After,Below},{Before,Above},{After,Above}};

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.1,VertexShapeFunction->"Square",ImagePadding->20,VertexLabels->Table[i->Placed["■■■",p],{i,0,2}],PlotLabel->p],{p,pl}]

Symbolic inside positions:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.45,VertexLabels->Table[i->Placed["■■■",p],{i,0,2}],VertexShapeFunction->"Square",PlotLabel->p],{p,{Left,Top,Right,Bottom}}]

Symbolic inside corner positions:

pl={{Left,Bottom},{Right,Bottom},{Left,Top},{Right,Top}};

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.45,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,0,2}],PlotLabel->p],{p,pl}]

Use explicit coordinates to place the center of labels:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.25,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,p],{i,0,2}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place all labels at the upper-right corner of the vertex and vary the coordinates within the label:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.35,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,{{1,1},p}],{i,0,2}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->{1->Placed[{"lbl1","lbl2"},{Above,Below}]}]

Any number of labels can be used:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->{1->Placed[{"lbl1","lbl2","lbl3","lbl4"},{Above,After,Below,Before}]}]

Use the argument (RefLink[Placed, paclet:ref/Placed]) to control formatting including (RefLink[Tooltip, paclet:ref/Tooltip]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->Placed["Name",Tooltip]]

Or (RefLink[StatusArea, paclet:ref/StatusArea]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->Placed["Name",StatusArea]]

Use more elaborate formatting functions:

rotateLabel[lbl_]:=Rotate[lbl,45Degree]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->Table[i->Placed["xxx",Below,rotateLabel],{i,0,2}]]

panelLabel[lbl_]:=Panel[lbl,FrameMargins->0,Background->Lighter[Yellow,0.7]]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->Table[i->Placed["xxx",Center,panelLabel],{i,0,2}]]

hyperlinkLabel[lbl_]:=Hyperlink[lbl,"http://www.wolfram.com"]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexLabels->Table[i->Placed["xxx",Center,hyperlinkLabel],{i,0,2}]]

OpenersExampleSubsection12(Spacer1)VertexShape  (5)

Use any (RefLink[Graphics, paclet:ref/Graphics]), (RefLink[Image, paclet:ref/Image]), or (RefLink[Graphics3D, paclet:ref/Graphics3D]) as a vertex shape:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShape->s,VertexSize->Medium],{s,{,,}}]

Specify vertex shapes for individual vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShape->{2->},VertexSize->Medium]

(RefLink[VertexShape, paclet:ref/VertexShape]) can be combined with (RefLink[VertexSize, paclet:ref/VertexSize]):

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->s,VertexShape->,PlotLabel->s],{s,{Small,Large}}]

(RefLink[VertexShape, paclet:ref/VertexShape]) is not affected by (RefLink[VertexStyle, paclet:ref/VertexStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexShape->,VertexStyle->Blue]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexShapeFunction->"Square",VertexShape->]

OpenersExampleSubsection13(Spacer1)VertexShapeFunction  (10)

Get a list of built-in collections for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

GraphElementData["Vertex"]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Basic" collection:

GraphElementData["Vertex","Basic"]

Simple basic shapes:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"Triangle","Square","Rectangle","Pentagon","Hexagon","Octagon"}}]

Common basic shapes:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"DownTrapezoid","UpTrapezoid","Parallelogram","FiveDown","Circle","Diamond","Star","Capsule"}}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Rounded" collection:

GraphElementData["Vertex","Rounded"]

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Rounded"]}]

Use built-in settings for (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) in the "Concave" collection:

GraphElementData["Vertex","Concave"]

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Concave"]}]

Draw individual vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->{ 1->"Square"},VertexSize->0.2]

Combine with a default vertex function:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->{ 1->"Square","Triangle"},VertexSize->0.2]

Draw vertices using a predefined graphic:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->(Inset[,#]&)]

Draw vertices by running a program:

vf[{xc_,yc_},name_,{w_,h_}]:=
Block[{xmin=xc-w,xmax=xc+w,ymin=yc-h,ymax=yc+h},
Polygon[{{xmin,ymin},{xmax,ymax},{xmin,ymax},{xmax,ymin}}]
];

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->vf,VertexSize->0.2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf1[{xc_,yc_},name_,{w_,h_}]:=Rectangle[{xc-w,yc-h},{xc+w,yc+h}]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf1]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf2[{xc_,yc_},name_,{w_,h_}]:={Red,Rectangle[{xc-w,yc-h},{xc+w,yc+h}]}

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexSize, paclet:ref/VertexSize]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexShapeFunction->"Star",VertexSize->{1->Small,Medium}]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexShape, paclet:ref/VertexShape]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.3,VertexShapeFunction->"Star",VertexShape->]

OpenersExampleSubsection14(Spacer1)VertexSize  (8)

By default, the size of vertices is computed automatically:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->Automatic]

Specify the size of all vertices using symbolic vertex size:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Use a fraction of the minimum distance between vertex coordinates:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->s,PlotLabel->s],{s,0.1,1,0.3}]

Use a fraction of the overall diagonal for all vertex coordinates:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->{"Scaled", s},PlotLabel->{"Scaled", s}],{s,0.1,1,0.3}]

Specify size in both the x and y directions:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->s,PlotLabel->s],{s,{{0.1,0.2},{0.2,0.1}}}]

Specify the size for individual vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->{1->0.2,2->0.3}]

(RefLink[VertexSize, paclet:ref/VertexSize]) can be combined with (RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]):

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->s,VertexShapeFunction->"Square",PlotLabel->s],{s,{0.05,0.1,0.2}}]

(RefLink[VertexSize, paclet:ref/VertexSize]) can be combined with (RefLink[VertexShape, paclet:ref/VertexShape]):

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->s,VertexShape->,PlotLabel->s],{s,{0.1,0.2,0.4}}]

OpenersExampleSubsection15(Spacer1)VertexStyle  (5)

Style all vertices:

Table[NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexStyle->style,VertexSize->0.3,PlotLabel->style],{style,{Yellow,EdgeForm[Dashed]}}]

Style individual vertices:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexStyle->{1->Blue,2->Red},VertexSize->0.2]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) can be combined with (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf1[{xc_,yc_},name_,{w_,h_}]:=Rectangle[{xc-w,yc-h},{xc+w,yc+h}]

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf1]

(RefLink[VertexShapeFunction, paclet:ref/VertexShapeFunction]) has higher priority than (RefLink[VertexStyle, paclet:ref/VertexStyle]):

vf2[{xc_,yc_},name_,{w_,h_}]:={Red,Rectangle[{xc-w,yc-h},{xc+w,yc+h}]}

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

(RefLink[VertexStyle, paclet:ref/VertexStyle]) can be combined with (RefLink[BaseStyle, paclet:ref/BaseStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexStyle->LightBlue,BaseStyle->EdgeForm[Dotted],VertexSize->0.2]

(RefLink[VertexStyle, paclet:ref/VertexStyle]) has higher priority than (RefLink[BaseStyle, paclet:ref/BaseStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexStyle->LightBlue,BaseStyle->Gray,VertexSize->0.2]

(RefLink[VertexShape, paclet:ref/VertexShape]) is not affected by (RefLink[VertexStyle, paclet:ref/VertexStyle]):

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexSize->0.2,VertexShape->,VertexStyle->Blue]

OpenersExampleSubsection16(Spacer1)VertexWeight  (2)

Set the weight for all vertices:

WheelGraph[4,VertexWeight->{2,3,4,5}]

PropertyValue[{%,1},VertexWeight]

Use any numeric expression as a weight:

NestGraph[Mod[#^2+1,5]&,Range[0,2],2,VertexWeight->{a,b,c}]

PropertyValue[{%,1},VertexWeight]

OpenersExampleSection3(Spacer1)Applications  (2)

Generate a network of "nearby" functions in the Wolfram Language:

NestGraph[WolframLanguageData[#,EntityProperty["WolframLanguageSymbol","RelatedSymbols"]]&,Entity["WolframLanguageSymbol","Nest"],2,VertexLabels->"Name"]

Visualize file systems:

NestGraph[FileNames["*",#] &, $InstallationDirectory,3,VertexLabels-> Placed["Name",Tooltip]]

OpenersExampleSection4(Spacer1)Properties & Relations  (5)

Use (RefLink[VertexCount, paclet:ref/VertexCount]) and (RefLink[EdgeCount, paclet:ref/EdgeCount]) to count vertices and edges:

g=NestGraph[Mod[#^2+1,10]&,{1,2,3,4,5},2]

{VertexCount[g],EdgeCount[g]}

Use (RefLink[VertexList, paclet:ref/VertexList]) and (RefLink[EdgeList, paclet:ref/EdgeList]) to enumerate vertices and edges in standard order:

g=NestGraph[WordData[#,"Synonyms","List"] &, "tree",2]

{VertexList[g],EdgeList[g]}

Compute the (RefLink[AdjacencyMatrix, paclet:ref/AdjacencyMatrix]) from a graph:

g=NestGraph[f,x,3];

AdjacencyMatrix[g]//MatrixForm

(RefLink[NeighborhoodGraph, paclet:ref/NeighborhoodGraph]) can be found by using (RefLink[NestGraph, paclet:ref/NestGraph]):

g=GridGraph[{4,4}];

g1 =NeighborhoodGraph[g,1,2]

g2=NestGraph[Rest@VertexOutComponent[g,#,1]&,1,2,DirectedEdges->False]//SimpleGraph

IsomorphicGraphQ[g1,g2]

Generate a tree of nested functions as lists:

NestList[{f[#],g[#]}&,x,3]

Generate as a graph:

NestGraph[{f[#],g[#]}&,x,3,VertexLabels->"Name"]

OpenersExampleSection5(Spacer1)Neat Examples  (1)

NestGraph[Range,{9},5]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Nest, paclet:ref/Nest])  ▪  (RefLink[Graph, paclet:ref/Graph])  ▪  (RefLink[NestList, paclet:ref/NestList])  ▪  (RefLink[NearestNeighborGraph, paclet:ref/NearestNeighborGraph])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Functional Programming, paclet:guide/FunctionalProgramming])}, {▪(RefLinkPlain[Functional Iteration, paclet:guide/FunctionalIteration])}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}, {▪(RefLinkPlain[Iterated Maps & Fractals, paclet:guide/IteratedMapsAndFractals])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/27-applying-functions-repeatedly.html])(WebLink[: Applying Functions Repeatedly, https://www.wolfram.com/language/elementary-introduction/27-applying-functions-repeatedly.html])}})}})