3
$\begingroup$

I would like to adjust the GraphLayout of the undirected graph given in the code below, which looks like the following figure:

enter image description here

Graph[{1, 2, 3, 4}, {{1, 2}, {1, 4}, {2, 3}, {3, 4}} // 
  Map[Apply[UndirectedEdge]], VertexWeight -> {1, 2, 3, 4}, 
 GraphLayout -> "CircularEmbedding", 
 VertexLabels -> Placed["Name", Center], VertexSize -> Medium, 
 VertexStyle -> {LightGray}, 
 VertexLabelStyle -> Directive[15, Black, Bold, Italic]]

Please any help. Thank you in advance.

$\endgroup$
2
  • $\begingroup$ try GraphLayout -> "GridEmbedding"? $\endgroup$
    – kglr
    Mar 7, 2023 at 15:00
  • $\begingroup$ @kglr No, it doesn't give me the required graph. Instead, "HighDimensionalEmbedding" works, but the position of the vertices are not balanced. $\endgroup$
    – user3840
    Mar 7, 2023 at 15:03

1 Answer 1

6
$\begingroup$

1. Use {"CircularEmbedding", "Offset" -> - 45 Degree} as the setting for GraphLayout:

Graph[{1, 2, 3, 4},
 {{1, 2}, {1, 4}, {2, 3}, {3, 4}} // Map[Apply[UndirectedEdge]], 
 GraphLayout -> {"CircularEmbedding", "Offset" -> - 45 Degree}, 
 VertexLabels -> Placed["Name", Center],
 VertexSize -> Medium, 
 VertexStyle -> {LightGray}, 
 VertexLabelStyle -> Directive[15, Black, Bold, Italic]]

enter image description here

2. Use {4,1,3,2} as the vertex list in the first argument of Graph and set GraphLayout -> "GridEmbedding":

Graph[{4, 1, 3, 2},
 {{1, 2}, {1, 4}, {2, 3}, {3, 4}} // Map[Apply[UndirectedEdge]], 
 GraphLayout -> "GridEmbedding", 
 VertexLabels -> Placed["Name", Center], VertexSize -> Medium, 
 VertexStyle -> {LightGray}, 
 VertexLabelStyle -> Directive[15, Black, Bold, Italic]]

enter image description here

$\endgroup$
0

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.