4
$\begingroup$

I have a graph such as

NestGraph[# + 1 &, 1, 10, GraphLayout -> "DiscreteSpiralEmbedding", 
 VertexShapeFunction -> "Name", VertexSize -> .2]

Mathematica graphics

But I want to revert the oder like:

Mathematica graphics

Can we do this in Mathematica?


Suggestion:

In spite of I konw when we do some calculate in a graph,its layout will not impact the result.But I think the layout of a graph is important sometiomes because of human have some demands such as aesthetics,intuition,figuration and so on.Maybe the nouns I use is not very exact,but we very care of its position usually.So I advice the people with permissions of SE establish a tag for this,such as "graph-layout".

$\endgroup$
2
  • $\begingroup$ NestGraph[# - 1 &, 11, 10, GraphLayout -> "DiscreteSpiralEmbedding", VertexShapeFunction -> "Name", VertexSize -> .2] Is this what you are asking? $\endgroup$
    – Prashanth
    Commented Mar 23, 2016 at 5:52
  • $\begingroup$ @Prashanth Actually I just simple this quetion.The graph in my case is like this,we cannot by #-1& to control it. $\endgroup$
    – yode
    Commented Mar 23, 2016 at 6:20

3 Answers 3

2
$\begingroup$

You can retrieve the vertex coordinates from the graph layout with GraphEmbedding (thanks to Dr. belisarius for pointing out this simpler alternative to PropertyValues):

g = PathGraph[Range[1, 11], 
  VertexShapeFunction -> "Name", VertexSize -> .2, 
  DirectedEdges -> True]

g = SetProperty[g, VertexCoordinates -> Reverse @ GraphEmbedding[
   g, 
   "DiscreteSpiralEmbedding"
]]

enter image description here

$\endgroup$
0
1
$\begingroup$

For any graph, you can do the following:

g = PathGraph[Range[1, 11], GraphLayout -> "DiscreteSpiralEmbedding", 
  VertexShapeFunction -> "Name", VertexSize -> .2, 
  DirectedEdges -> True]

Mathematica graphics

Graph[Reverse /@ EdgeList@g, GraphLayout -> "DiscreteSpiralEmbedding",
  VertexShapeFunction -> "Name", VertexSize -> .2, 
 DirectedEdges -> True]

Mathematica graphics

$\endgroup$
10
  • $\begingroup$ Just the direction be reverse too.Like the original graph such as 1->2,2->3..We just adjust its layout but direction. $\endgroup$
    – yode
    Commented Mar 23, 2016 at 6:18
  • $\begingroup$ @yode Sorry, I am not able to understand your English $\endgroup$ Commented Mar 23, 2016 at 6:25
  • $\begingroup$ I feel so ashamed of it sometimes,but I'm in learning English very hardly recently . :) $\endgroup$
    – yode
    Commented Mar 23, 2016 at 6:29
  • $\begingroup$ @yode Don't worry. My English is tarzanic too. Perhaps a native speaker will be able to answer then. $\endgroup$ Commented Mar 23, 2016 at 6:32
  • 3
    $\begingroup$ @MartinBüttner Like this SetProperty[g, VertexCoordinates -> Reverse@GraphEmbedding[g]] ?? $\endgroup$ Commented Mar 23, 2016 at 8:45
1
$\begingroup$
NestGraph[# + 1 &, 1, 10,
 GraphLayout -> {"DiscreteSpiralEmbedding", "OptimalOrder" -> False},
 VertexShapeFunction -> "Name", VertexSize -> .2]

or

PathGraph[Range@11, 
 GraphLayout -> {"DiscreteSpiralEmbedding", "OptimalOrder" -> False}, 
 VertexShapeFunction -> "Name", VertexSize -> .2, DirectedEdges -> True]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ As the documentation."With the setting "OptimalOrder"->True, the vertex ordering optimizes the angular resolution and the aspect ratio".The OptimalOrder give a perfect solution,but I don't know what did it here. $\endgroup$
    – yode
    Commented Mar 23, 2016 at 9:19
  • $\begingroup$ Anyway,I have give a upvote. $\endgroup$
    – yode
    Commented Mar 23, 2016 at 9:26
  • $\begingroup$ I found the OptimalOrder don't always reverse the order such as Graph[Table[i<->i+1,{i,11}],GraphLayout->{ "DiscreteSpiralEmbedding","OptimalOrder"->False},VertexLabels->"Name"],The OptimalOrder->False is same to OptimalOrder->True. $\endgroup$
    – yode
    Commented Mar 23, 2016 at 17:48

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.