({{, (RefLink[RelationGraph, paclet:ref/RelationGraph])[f,{(Subscript[v, 1]),(Subscript[v, 2]),…}]
gives the graph with vertices (Subscript[v, i]) and edges from (Subscript[v, i]) to (Subscript[v, j]) whenever f[(Subscript[v, i]),(Subscript[v, j])] is (RefLink[True, paclet:ref/True]).}, {, (RefLink[RelationGraph, paclet:ref/RelationGraph])[f,{(Subscript[v, 1]),(Subscript[v, 2]),…},{(Subscript[w, 1]),(Subscript[w, 2]),…}]
gives the graph with vertices (Subscript[v, i]),(Subscript[w, j]) and edges from (Subscript[v, i]) to (Subscript[w, j]) whenever f[(Subscript[v, i]),(Subscript[w, j])] is (RefLink[True, paclet:ref/True]).}})

OpenersNotesSection(Spacer1)Details and Options

RelationalGraph 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.

The following settings for (RefLink[DirectedEdges, paclet:ref/DirectedEdges]) can be used in RelationalGraph:

OpenersPrimaryExamplesSection(Spacer1)Examples  (104)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Construct a bipartite graph:

RelationGraph[#1<6&& #2≥ 6&, {1,2,3,4,5,6,7,8}]

A coprime graph:

RelationGraph[CoprimeQ, {1,2,3,4,5,6,7},GraphLayout-> "LayeredDigraphEmbedding"]

OpenersExampleSection1(Spacer1)Scope  (4)

(RefLink[RelationGraph, paclet:ref/RelationGraph]) works with any binary Boolean function:

RelationGraph[CoprimeQ, {1,2,3,4,5,6,7}]

Boolean expressions:

f[i_,j_]:=(i  =!= j) && Divisible[i,j]

RelationGraph[f,Divisors[24]]

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

RelationGraph[#1<6&& #2≥ 6&, {1,2,3,4,5,6,7,8}]

Strings:

RelationGraph[StringFreeQ,{"a","ab","abc","abcd"}]

Define a binary relation between two sets:

RelationGraph[#1<6&& #2≥ 6&, {1,2,3,4,5},{6,7,8}]

By default, a symmetric relation generates an undirected graph:

RelationGraph[CoprimeQ, Range[4]]

A nonsymmetric relation generates a directed graph:

RelationGraph[Greater, Range[4]]

OpenersExampleSection2(Spacer1)Options  (82)

OpenersExampleSubsection0(Spacer1)DirectedEdges  (3)

By default, a symmetric relation generates an undirected graph:

RelationGraph[Unequal,{1,2,3}]

Use (RefLink[DirectedEdges, paclet:ref/DirectedEdges])->(RefLink[True, paclet:ref/True]) to generate a directed graph:

RelationGraph[Unequal,{1,2,3},DirectedEdges->True]

By default, a nonsymmetric matrix generates a directed graph:

RelationGraph[Greater,{1,2,3,4}]

OpenersExampleSubsection1(Spacer1)EdgeLabels  (7)

Label the edge 1<->2:

RelationGraph[Unequal,{1,2,3},EdgeLabels->{1\[UndirectedEdge]2->"Hello"}]

Label all edges individually:

el=EdgeList@RelationGraph[Unequal,{1,2,3}]

RelationGraph[Unequal,{1,2,3},EdgeLabels->Table[el[[i]]->(Subscript["e", i]),{i,Length[el]}]]

Use any expression as a label:

RelationGraph[Unequal,{1,2,3},EdgeLabels->{1\[UndirectedEdge]2->,2\[UndirectedEdge]3->,3\[UndirectedEdge]1-> }]

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

Table[RelationGraph[Unequal,{1,2,3},EdgeLabels->{1\[UndirectedEdge]2->Placed["■■■",p]},PlotLabel->p],{p,{"Start","Middle","End"}}]

Use explicit coordinates to place labels:

Table[RelationGraph[Unequal,{1,2,3},EdgeLabels->{2\[UndirectedEdge]3->Placed["■■■",p]},PlotLabel->p,BaselinePosition->Bottom],{p,{0,1/4,1/3}}]

Vary positions within the label:

Table[RelationGraph[Unequal,{1,2,3},EdgeLabels->{2\[UndirectedEdge]3->Placed["■■■",{1/2,p}]},PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels:

RelationGraph[Unequal,{1,2,3},EdgeLabels->{3\[UndirectedEdge]1->Placed[{"lbl1","lbl2"},{"Start","End"}]}]

RelationGraph[Unequal,{1,2,3},EdgeLabels->{3\[UndirectedEdge]1->Placed[{"lbl1","lbl2","lbl3"},{"Start","Middle","End"}]}]

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

RelationGraph[Unequal,{1,2,3},EdgeLabels->Placed["Name",Tooltip]]

RelationGraph[Unequal,{1,2,3},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:

RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->"Line"]

Lines with different glyphs on the edges:

Table[RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,{"BoxLine","DiamondLine","DotLine"}}]

Directed edges including solid arrows:

Table[RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","FilledArrow"]}]

Line arrows:

Table[RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","UnfilledArrow"]}]

Open arrows:

Table[RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->GraphElementData[ef,"ArrowSize"->0.1],PlotLabel->ef],{ef,GraphElementData["Edge","CarvedArrow"]}]

Specify an edge function for an individual edge:

RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->{1\[UndirectedEdge]2->"DotLine"}]

Combine with a different default edge function:

RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->{1\[UndirectedEdge]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]}]

RelationGraph[Unequal,{1,2,3},EdgeShapeFunction->ef]

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

RelationGraph[Unequal,{1,2,3},EdgeStyle->Blue,EdgeShapeFunction->(Line[#1]&)]

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

RelationGraph[Unequal,{1,2,3},EdgeStyle->Blue,EdgeShapeFunction->({Red,Line[#1]}&)]

OpenersExampleSubsection3(Spacer1)EdgeStyle  (2)

Style all edges:

Table[RelationGraph[Unequal,{1,2,3},EdgeStyle->style,PlotLabel->style],{style,{Gray,Dashed,Thick}}]

Style individual edges:

RelationGraph[Unequal,{1,2,3},EdgeStyle->{1\[UndirectedEdge]2->Blue,1\[UndirectedEdge]3->Dashed}]

OpenersExampleSubsection4(Spacer1)EdgeWeight  (2)

Specify a weight for all edges:

RelationGraph[Unequal,{1,2,3},EdgeWeight->RandomInteger[5,3]]

WeightedAdjacencyMatrix[%]//MatrixForm

Use any numeric expression as a weight:

RelationGraph[Unequal,{1,2,3},EdgeWeight->{a,b,c}]

WeightedAdjacencyMatrix[%]//MatrixForm

OpenersExampleSubsection5(Spacer1)GraphHighlight  (3)

Highlight the vertex 1:

RelationGraph[(#1 !=#2)&,Range[3],VertexSize->Tiny,GraphHighlight->{1}]

Highlight the edge 2<->3:

RelationGraph[Unequal,{1,2,3},VertexSize->Tiny,GraphHighlight->{2\[UndirectedEdge]3}]

Highlight vertices and edges:

RelationGraph[Unequal,{1,2,3},VertexSize->Tiny,GraphHighlight->{1,2,1\[UndirectedEdge]2,2\[UndirectedEdge]3}]

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]):

RelationGraph[Unequal,{1,2,3},GraphHighlight->{1,2\[UndirectedEdge]3},VertexSize->Small,GraphHighlightStyle->#,PlotLabel->#]&/@Select[GraphElementData["GraphHighlightStyle"],#=!=Automatic&]

OpenersExampleSubsection7(Spacer1)GraphLayout  (5)

By default, the layout is chosen automatically:

RelationGraph[Unequal,Range[10],GraphLayout->Automatic]

Specify layouts on special curves:

Table[RelationGraph[Unequal,Range[10],GraphLayout->l,PlotLabel->l],{l,{"CircularEmbedding","SpiralEmbedding"}}]

Specify layouts that satisfy optimality criteria:

Table[RelationGraph[Unequal,Range[10],GraphLayout->l,PlotLabel->l],{l,{"SpringEmbedding","SpringElectricalEmbedding","HighDimensionalEmbedding"}}]

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

{RelationGraph[Unequal,Range[4],GraphLayout->"SpringElectricalEmbedding"],
RelationGraph[(#1 !=#2)&,Range[4],GraphLayout->"SpringElectricalEmbedding",VertexCoordinates->Table[{i,i},{i,0,3}]]}

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

RelationGraph[Unequal,Range[4]]

AbsoluteOptions[%,VertexCoordinates]

OpenersExampleSubsection8(Spacer1)PlotTheme  (4)

OpenersExampleSubsubsection0(Spacer1)Base Themes  (2)

Use a common base theme:

RelationGraph[Unequal,{1,2,3},PlotTheme->"Business"]

Use a monochrome theme:

RelationGraph[Unequal,{1,2,3},PlotTheme->"Monochrome"]

OpenersExampleSubsubsection1(Spacer1)Feature Themes  (2)

Use a large graph theme:

RelationGraph[Unequal,{1,2,3},PlotTheme->"LargeGraph"]

Use a classic diagram theme:

RelationGraph[Unequal,{1,2,3},PlotTheme->"ClassicDiagram"]

OpenersExampleSubsection9(Spacer1)Properties  (2)

Specify a property for vertices:

RelationGraph[Unequal,{1,2,3},Properties->{1->{VertexLabels-> "hello"}}]

Edges:

RelationGraph[Unequal,{1,2,3},Properties->{1\[UndirectedEdge]2->{EdgeLabels-> "hello"}}]

OpenersExampleSubsection10(Spacer1)VertexCoordinates  (3)

By default, any vertex coordinates are computed automatically:

RelationGraph[Unequal,{1,2,3}]

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[10,{2,1}]]]

Use it to generate vertex coordinates for a graph:

RelationGraph[Unequal,Range[10],VertexCoordinates->ellipseLayout[10,{2,1}]]

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

RelationGraph[Unequal,Range[4],VertexCoordinates->Table[{i,i},{i,4}],GraphLayout->"CircularEmbedding"]

OpenersExampleSubsection11(Spacer1)VertexLabels  (13)

Use vertex names as labels:

RelationGraph[Unequal,{1,2,3},VertexLabels->"Name"]

Label individual vertices:

RelationGraph[Unequal,{1,2,3},VertexLabels->{2->"one"}]

Label all vertices:

RelationGraph[Unequal,{1,2,3},VertexLabels->Table[i->(Subscript[v, i]),{i,3}]]

Use any expression as a label:

RelationGraph[Unequal,{1,2,3},VertexLabels->{1->,2->,3->},ImagePadding->20]

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

Table[RelationGraph[Unequal,{1,2,3},VertexSize->0.1,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,3}],PlotLabel->p,ImagePadding->20],{p,{Before,After,Below,Above}}]

Symbolic outside corner positions:

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

Table[RelationGraph[Unequal,{1,2,3},VertexSize->0.1,VertexShapeFunction->"Square",ImagePadding->20,VertexLabels->Table[i->Placed["■■■",p],{i,3}],PlotLabel->p],{p,pl}]

Symbolic inside positions:

Table[RelationGraph[Unequal,{1,2,3},VertexSize->0.45,VertexLabels->Table[i->Placed["■■■",p],{i,3}],VertexShapeFunction->"Square",PlotLabel->p],{p,{Left,Top,Right,Bottom}}]

Symbolic inside corner positions:

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

Table[RelationGraph[Unequal,{1,2,3},VertexSize->0.45,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed["■■■",p],{i,3}],PlotLabel->p],{p,pl}]

Use explicit coordinates to place the center of labels:

Table[RelationGraph[Unequal,{1,2,3},VertexSize->0.25,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,p],{i,3}],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[RelationGraph[Unequal,{1,2,3},VertexSize->0.35,VertexShapeFunction->"Square",VertexLabels->Table[i->Placed[,{{1,1},p}],{i,3}],PlotLabel->p,BaselinePosition->Bottom],{p,{{0,0},{1/2,1/2},{1,1}}}]

Place multiple labels:

RelationGraph[Unequal,{1,2,3},VertexLabels->{1->Placed[{"lbl1","lbl2"},{Above,Below}]}]

Any number of labels can be used:

RelationGraph[Unequal,{1,2,3},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]):

RelationGraph[Unequal,{1,2,3},VertexLabels->Placed["Name",Tooltip]]

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

RelationGraph[Unequal,{1,2,3},VertexLabels->Placed["Name",StatusArea]]

Use more elaborate formatting functions:

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

RelationGraph[Unequal,{1,2,3},VertexLabels->Table[i->Placed["xxx",Below,rotateLabel],{i,3}]]

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

RelationGraph[Unequal,{1,2,3},VertexLabels->Table[i->Placed["xxx",Center,panelLabel],{i,3}]]

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

RelationGraph[Unequal,{1,2,3},VertexLabels->Table[i->Placed["xxx",Center,hyperlinkLabel],{i,3}]]

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[RelationGraph[Unequal,{1,2,3},VertexShape->s,VertexSize->Medium],{s,{,,}}]

Specify vertex shapes for individual vertices:

RelationGraph[Unequal,{1,2,3},VertexShape->{2->},VertexSize->Medium]

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

Table[RelationGraph[Unequal,{1,2,3},VertexSize->s,VertexShape->,PlotLabel->s],{s,{Small,Large}}]

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

RelationGraph[Unequal,{1,2,3},VertexSize->0.2,VertexShape->,VertexStyle->Blue]

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

RelationGraph[Unequal,{1,2,3},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[RelationGraph[Unequal,{1,2,3},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,{"Triangle","Square","Rectangle","Pentagon","Hexagon","Octagon"}}]

Common basic shapes:

Table[RelationGraph[Unequal,{1,2,3},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[RelationGraph[Unequal,{1,2,3},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[RelationGraph[Unequal,{1,2,3},VertexShapeFunction->vf,VertexSize->0.2,PlotLabel->vf],{vf,GraphElementData["Vertex","Concave"]}]

Draw individual vertices:

RelationGraph[Unequal,{1,2,3},VertexShapeFunction->{ 1->"Square"},VertexSize->0.2]

Combine with a default vertex function:

RelationGraph[Unequal,{1,2,3},VertexShapeFunction->{ 1->"Square","Triangle"},VertexSize->0.2]

Draw vertices using a predefined graphic:

RelationGraph[Unequal,{1,2,3},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}}]
];

RelationGraph[Unequal,{1,2,3},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}]

RelationGraph[Unequal,{1,2,3},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}]}

RelationGraph[Unequal,{1,2,3},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

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

RelationGraph[Unequal,{1,2,3},VertexShapeFunction->"Star",VertexSize->{1->Small,Medium}]

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

RelationGraph[Unequal,{1,2,3},VertexSize->0.3,VertexShapeFunction->"Star",VertexShape->]

OpenersExampleSubsection14(Spacer1)VertexSize  (8)

By default, the size of vertices is computed automatically:

RelationGraph[Unequal,{1,2,3},VertexSize->Automatic]

Specify the size of all vertices using symbolic vertex size:

Table[RelationGraph[Unequal,{1,2,3},VertexSize->s,PlotLabel->s],{s,{Tiny,Small,Medium,Large}}]

Use a fraction of the minimum distance between vertex coordinates:

Table[RelationGraph[Unequal,{1,2,3},VertexSize->s,PlotLabel->s],{s,0.1,1,0.3}]

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

Table[RelationGraph[Unequal,{1,2,3},VertexSize->{"Scaled", s},PlotLabel->{"Scaled", s}],{s,0.1,1,0.3}]

Specify size in both the x and y directions:

Table[RelationGraph[Unequal,{1,2,3},VertexSize->s,PlotLabel->s],{s,{{0.1,0.2},{0.2,0.1}}}]

Specify the size for individual vertices:

RelationGraph[Unequal,{1,2,3},VertexSize->{1->0.2,2->0.3}]

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

Table[RelationGraph[Unequal,{1,2,3},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[RelationGraph[Unequal,{1,2,3},VertexSize->s,VertexShape->,PlotLabel->s],{s,{0.1,0.2,0.4}}]

OpenersExampleSubsection15(Spacer1)VertexStyle  (5)

Style all vertices:

Table[RelationGraph[Unequal,{1,2,3},VertexStyle->style,VertexSize->0.3,PlotLabel->style],{style,{Yellow,EdgeForm[Dashed]}}]

Style individual vertices:

RelationGraph[Unequal,{1,2,3},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}]

RelationGraph[Unequal,{1,2,3},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}]}

RelationGraph[Unequal,{1,2,3},VertexSize->0.2,VertexStyle->Blue,VertexShapeFunction->vf2]

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

RelationGraph[Unequal,{1,2,3},VertexStyle->LightBlue,BaseStyle->EdgeForm[Dotted],VertexSize->0.2]

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

RelationGraph[Unequal,{1,2,3},VertexStyle->LightBlue,BaseStyle->Gray,VertexSize->0.2]

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

RelationGraph[Unequal,{1,2,3},VertexSize->0.2,VertexShape->,VertexStyle->Blue]

OpenersExampleSubsection16(Spacer1)VertexWeight  (2)

Set the weight for all vertices:

RelationGraph[Unequal,{1,2,3},VertexWeight->{2,3,4}]

PropertyValue[{%,1},VertexWeight]

Use any numeric expression as a weight:

RelationGraph[Unequal,{1,2,3},VertexWeight->{a,b,c}]

PropertyValue[{%,1},VertexWeight]

OpenersExampleSection3(Spacer1)Applications  (12)

Construct a suffix graph:

suffixQ[s1_,s2_]:=StringMatchQ[s1,___~~s2]

RelationGraph[suffixQ,{"d","cd","bcd","abcd"}]

Construct a prefix graph:

prefixQ[s1_,s2_]:=StringMatchQ[s1,s2~~___]

RelationGraph[prefixQ,{"a","ab","abc","abcd"}]

Construct a substring graph:

substringQ[s1_,s2_]:=UnsameQ[s1 ,s2] && StringMatchQ[s1,___~~s2~~___]

RelationGraph[substringQ,{"a","b","c","ab","ac","bc","abc"}]

Generate a network of "nearby" words in a dictionary:

words=DictionaryLookup["wol*"];

RelationGraph[#1=!=#2 &&MemberQ[Nearest[words,#2,3],#1]&,words,VertexLabels->"Name"]

Construct a divisibility graph:

RelationGraph[Divisible,{2,3,4,6,8,12}]

Construct a coprime graph:

RelationGraph[CoprimeQ, {1,2,3,4,5,6}]

Connect a number to another that is one bit reversed:

RelationGraph[(#2==FromDigits[Reverse[IntegerDigits[#1,2]],2])&,Range[2^8-1]]

Connect a number to another that is one bit rotated right:

RelationGraph[(#2==FromDigits[RotateRight[IntegerDigits[#1,2]],2])&,Range[2^8-1]]

Connect a number to itself but with the first bit dropped:

RelationGraph[(#2==FromDigits[Drop[IntegerDigits[#1,2],-1],2])&,Range[2^8-1]]

Visualize self-loops in a reflexive relation:

HighlightGraph[RelationGraph[LessEqual, {1,2,3,4,5}],a_\[DirectedEdge]a_]

Visualize a transitive relation:

HighlightGraph[RelationGraph[LessEqual, {1,2,3,4,5}],{1\[DirectedEdge]2,2\[DirectedEdge]3}]

Find the adjacent countries in South America:

countries=CountryData["SouthAmerica"];

RelationGraph[MemberQ[CountryData[#2,"BorderingCountries"],#1]&,countries,VertexLabels->"Name"]

OpenersExampleSection4(Spacer1)Properties & Relations  (4)

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

g=RelationGraph[CoprimeQ, {1,2,3,4,5,6,7}]

{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=RelationGraph[StringFreeQ,{"a","ab","abc","abcd"}]

{VertexList[g],EdgeList[g]}

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

g=RelationGraph[CoprimeQ, {1,2,3,4,5,6,7}];

AdjacencyMatrix[g]//MatrixForm

Use (RefLink[RelationGraph, paclet:ref/RelationGraph]) to construct a graph from its adjacency matrix:

m={{0,1,0},{0,0,1},{1,0,0}};

RelationGraph[ m[[#1,#2]]==1&,Range[First[Dimensions[m]]]]

Use (RefLink[AdjacencyGraph, paclet:ref/AdjacencyGraph]):

AdjacencyGraph[m]

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Graph Construction & Representation, paclet:guide/GraphConstructionAndRepresentation])}})}})