Graph: ordered vertices

I have tried things like

With[{coords=Most@With[{n=23,\[Theta] = LambertW[1] },
N@(Table[{{Re[E^( I \[Theta])], -Im[E^( I \[Theta])]},
{Im[E^( I \[Theta])], Re[E^( I \[Theta])]}}.{Re[ E^(I (1 + 2 \[Pi] ii/n))],
Im[E^(I (1 + 2 \[Pi] ii/n))]}, {ii, Join[{n}, Range[n]]}])]},
Graph[{1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 7 -> 9, 8 -> 17,
9 -> 16, 10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 14 -> 22, 15 -> 21,
16 -> 20, 17 -> 19, 18 -> 7, 19 -> 6, 20 -> 5, 21 -> 4, 22 -> 3,
23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 14 -> 2, 15 -> 1},
DirectedEdges -> False, VertexLabels -> “Name”, VertexCoordinates->coords ]]

which generates a graph with vertices out of order (I suppose coords must not be generated as I expected)

I have tried other things like GraphLayout -> {“CircularEmbedding”}, but that doesn’t work either.

Have even tried

n=23;With[{coords=With[{polygon=Most@With[{\[Theta] = LambertW[1] },
N@(Table[{{Re[E^( I \[Theta])], -Im[E^( I \[Theta])]},
{Im[E^( I \[Theta])], Re[E^( I \[Theta])]}}.{Re[ E^(I (1 + 2 \[Pi] ii/n))],
Im[E^(I (1 + 2 \[Pi] ii/n))]}, {ii, Join[{n}, Range[n]]}])]},
With[{ points = N@RandomSample[Join[polygon, {{0, 0}}]]},
With[{ chm=ConvexHullMesh[points]},
With[{ ordering=MeshCells[chm,2][[1,1]]},
MeshCoordinates[chm][[ordering]]]]]]},
Graph[{1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 7 -> 9, 8 -> 17,
9 -> 16, 10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 14 -> 22, 15 -> 21,
16 -> 20, 17 -> 19, 18 -> 7, 19 -> 6, 20 -> 5, 21 -> 4, 22 -> 3,
23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 14 -> 2, 15 -> 1},
DirectedEdges -> False, VertexLabels -> “Name”, VertexCoordinates->coords ]]

so I don’t think its a problem with coords, but with graph order.

=================

1

 

related Q/A:Ordering vertices in GraphPlot; some answers that also cover the Graph case.
– kglr
Mar 13 ’15 at 10:52

=================

2 Answers
2

=================

The vertex coordinates are applied to the vertexes in the order they are given, including the target nodes. Therefore 3 ends up before 2 and takes its position.

A way to correct your layout:

coords = Most@
With[{n = 23, θ = LambertW[1]},
N@(Table[{{Re[E^(I θ)], -Im[E^(I θ)]}, {Im[E^(I θ)],
Re[E^(I θ)]}}.{Re[E^(I (1 + 2 π ii/n))],
Im[E^(I (1 + 2 π ii/n))]}, {ii, Join[{n}, Range[n]]}])];

verts = {1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 7 -> 9, 8 -> 17, 9 -> 16,
10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 14 -> 22, 15 -> 21, 16 -> 20, 17 -> 19,
18 -> 7, 19 -> 6, 20 -> 5, 21 -> 4, 22 -> 3, 23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3,
14 -> 2, 15 -> 1};

ord = DeleteDuplicates[Join @@ List @@@ verts];

Graph[verts, DirectedEdges -> False, VertexLabels -> “Name”,
VertexCoordinates -> coords[[ord]]
]

In the words of the documentation:

Graph[verts] // VertexList

{1, 3, 2, 7, 6, 4, 5, 11, 10, 9, 8, 17, 16, 15, 14, 12, 13, 23, 22, 21, 20, 19, 18}

  

 

ah! I knew it was something I wasn’t understanding! 🙂
– martin
Mar 13 ’15 at 9:06

1

 

@martin I added a documentation reference.
– Mr.Wizard♦
Mar 13 ’15 at 9:07

  

 

@martin Try: VertexCoordinates -> Reverse[coords][[ord]]
– Mr.Wizard♦
Mar 13 ’15 at 9:12

Just supply vertices when you define graph:

With[{coords =
Most@With[{n = 23, \[Theta] = LambertW[1]},
N@(Table[{{Re[E^(I \[Theta])], -Im[E^(I \[Theta])]}, {Im[
E^(I \[Theta])], Re[E^(I \[Theta])]}}.{Re[
E^(I (1 + 2 \[Pi] ii/n))],
Im[E^(I (1 + 2 \[Pi] ii/n))]}, {ii,
Join[{n}, Range[n]]}])]},
Graph[Range[23], {1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10,
7 -> 9, 8 -> 17, 9 -> 16, 10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23,
14 -> 22, 15 -> 21, 16 -> 20, 17 -> 19, 18 -> 7, 19 -> 6, 20 -> 5,
21 -> 4, 22 -> 3, 23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 14 -> 2,
15 -> 1}, DirectedEdges -> False, VertexLabels -> “Name”,
VertexCoordinates -> coords]]

  

 

so simple! Great! 🙂
– martin
Mar 13 ’15 at 16:18