9
$\begingroup$

I have this graph:

Graph[{a <-> 1, a <-> 2, a <-> 3, a <-> 4, b <-> 5, b <-> 6, 
  b <-> 7, b <-> 8, c <-> 9, c <-> 10, c <-> 11, c <-> 12, d <-> 13, 
  d <-> 14, d <-> 15, d <-> 16, a <-> b, a <-> c, a <-> d, b <-> c, 
  b <-> d, c <-> d, 1 <-> i, 2 <-> j, 3 <-> k, 4 <-> l, 5 <-> m, 
  6 <-> n, 7 <-> o, 8 <-> p, 9 <-> q, 10 <-> r, 11 <-> s, 12 <-> t, 
  13 <-> u, 14 <-> v, 15 <-> w, 16 <-> x, a <-> M, b <-> M, c <-> M, 
  d <-> M}

When the graph is generated in Mathematica, the node in the center of the graph (vertex M) is placed above the point where the two edges a<->c and b<->d cross. This hides some information: it is not clear that {a,b,c,d} are fully connected. How can I make Mathematica change the graphical position of M?

$\endgroup$
  • $\begingroup$ Try GraphLayout, e.g. CircularEmbedding or DiscreteSpiralEmbedding might be useful. $\endgroup$ – ciao May 22 '14 at 9:35
7
$\begingroup$
g = Graph[{a <-> 1, a <-> 2, a <-> 3, a <-> 4, b <-> 5, b <-> 6, 
   b <-> 7, b <-> 8, c <-> 9, c <-> 10, c <-> 11, c <-> 12, d <-> 13, 
   d <-> 14, d <-> 15, d <-> 16, a <-> b, a <-> c, a <-> d, b <-> c, 
   b <-> d, c <-> d, 1 <-> i, 2 <-> j, 3 <-> k, 4 <-> l, 5 <-> m, 
   6 <-> n, 7 <-> o, 8 <-> p, 9 <-> q, 10 <-> r, 11 <-> s, 12 <-> t, 
   13 <-> u, 14 <-> v, 15 <-> w, 16 <-> x, a <-> M, b <-> M, c <-> M, 
   d <-> M}, VertexLabels -> "Name"]

Mathematica graphics

SetProperty[{g, M}, VertexCoordinates -> {2.45, 2.8}]

Mathematica graphics

Or like rasher noted you can play with GraphLayout but It's pretty ugly IMO (GraphLayout -> "DiscreteSpiralEmbedding" below):

Mathematica graphics

$\endgroup$
3
$\begingroup$

An alternative approach is to keep the vertex coordinates and change the edge shapes:

g1 = Graph[{a <-> 1, a <-> 2, a <-> 3, a <-> 4, b <-> 5, b <-> 6, 
    b <-> 7, b <-> 8, c <-> 9, c <-> 10, c <-> 11, c <-> 12, d <-> 13,
    d <-> 14, d <-> 15, d <-> 16, a <-> b, a <-> c, a <-> d, b <-> c,
    b <-> d, c <-> d, 1 <-> i, 2 <-> j, 3 <-> k, 4 <-> l, 5 <-> m, 
    6 <-> n, 7 <-> o, 8 <-> p, 9 <-> q, 10 <-> r, 11 <-> s, 12 <-> t, 
    13 <-> u, 14 <-> v, 15 <-> w, 16 <-> x, a <-> M, b <-> M, c <-> M,
    d <-> M}, VertexLabels -> "Name",  ImagePadding -> 10, ImageSize -> 360];

g2 = SetProperty[g1, EdgeShapeFunction -> (_ <-> M | c <-> d | b <-> a -> 
       GraphElementData[{"CurvedArc", "Curvature" -> 1/2}])];

Row[{g1, g2}]

enter image description here

Alternatively, just change the two edges or all edges:

g3 = SetProperty[g1, 
    EdgeShapeFunction -> (c <-> d | b <-> a -> {"CurvedArc",  "Curvature" -> 1/2})];
g4 = SetProperty[g1, 
   EdgeShapeFunction -> {"CurvedArc", "Curvature" -> 1/2}];
Row[{g3, g4}]

enter image description here

$\endgroup$
  • $\begingroup$ As always, this is very good! :) $\endgroup$ – Öskå Aug 1 '17 at 15:59
  • $\begingroup$ Thank you @Öskå. $\endgroup$ – kglr Aug 1 '17 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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