4
$\begingroup$

If have the following code.

AdjacencyGraph[Table[Boole[CoprimeQ[i - j, 8]], {j, 0, 7}, {i, 0, 7}]]

This generates a graph with 8 vertices. If the vertices are labeled 0, 1, ..., 7, where two vertices are adjacent whenever their difference is relatively prime to 8 (so 3 and 6 are adjacent since 6 - 3 = 3 is relatively prime to 8). I would like to have the graph drawn so that the vertices are in specific positions. Specifically, I would like to have the vertices 0, 1, ..., 7 evenly spaced around a circle in this order. In other words, this the graph should look like a regular octagon with additional edges inside. Is there a way to modify my code so that the vertices get drawn in this way?

$\endgroup$

1 Answer 1

4
$\begingroup$

You can use the option GraphLayout -> "CircularEmbedding":

k = 7;
AdjacencyGraph[Range[0, k], 
 Table[Boole[CoprimeQ[i - j, k + 1]], {j, 0, k}, {i, 0, k}], 
 GraphLayout -> "CircularEmbedding", 
 VertexLabels -> Placed["Name", Center], VertexSize -> Medium]

enter image description here

You can also use RelationGraph to get the same result:

RelationGraph[CoprimeQ[# - #2, k + 1] &, Range[0, k], 
 GraphLayout -> "CircularEmbedding", 
 VertexLabels -> Placed["Name", Center], VertexSize -> Medium]

same picture

$\endgroup$
2
  • 1
    $\begingroup$ Is it true? k = 7; AdjacencyGraph[Range[0, k], Table[Boole[CoprimeQ[i - j, k + 1]], {j, 0, k}, {i, 0, k}], GraphLayout -> "CircularEmbedding", VertexLabels -> Placed["Name", Center], VertexSize -> Medium] $\endgroup$ Commented Feb 12, 2019 at 7:39
  • $\begingroup$ @minhthien_2016, yes. $\endgroup$
    – kglr
    Commented Feb 12, 2019 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.