4
$\begingroup$

I would like to draw a graph in circular layout but I would like to position the vertices in descending order on the circle. Can this be done in an easy way?

$\endgroup$

3 Answers 3

5
$\begingroup$

Sort the vertices first. Here is an example graph:

SeedRandom[1]
g = RandomGraph[{20,40}]

enter image description here

We can use DegreeCentrality to get all of the degrees:

DegreeCentrality[g]

{5, 4, 5, 4, 6, 2, 4, 3, 1, 4, 4, 3, 5, 4, 5, 2, 4, 3, 5, 7}

So, the following should do what you want:

Graph[
    VertexList[g][[Ordering[DegreeCentrality[g]]]],
    EdgeList[g],
    GraphLayout->"CircularEmbedding"
]

enter image description here

$\endgroup$
1
  • $\begingroup$ Any reason you chose DegreeCentrality over VertexDegree? $\endgroup$
    – Greg Hurst
    Jul 23, 2018 at 5:21
4
$\begingroup$

Suppose you already have some graph properties (such as edge or vertex weights) or some graph styling. The IGReorderVertices convenience function from IGraph/M makes it easy to preserve these properties during reordering.

Here's a styled graph:

g = RandomGraph[BarabasiAlbertGraphDistribution[20, 3], VertexSize -> Large, EdgeStyle -> Gray] // 
  IGVertexMap[ColorData["SolarColors"], VertexStyle -> Rescale@*VertexDegree]

enter image description here

And here it is with circular layout:

IGReorderVertices[
  VertexList[g][[ Ordering@VertexDegree[g] ]], 
  Graph[g, GraphLayout -> "CircularEmbedding"]
]

enter image description here

$\endgroup$
4
$\begingroup$

GraphPropertyChart

GraphComputation`GraphPropertyChart is an alternative way to visualize vertex degree centralities using a circular layout.

Using Carl Wolls' example:

SeedRandom[1]
g = RandomGraph[{20, 40}]; 
dc = DegreeCentrality[g];
ordering = Ordering[dc];

GraphComputation`GraphPropertyChart[g, Automatic -> dc[[ordering]],
  ChartLabels -> {Placed[{dc[[ordering]], ordering}, {"RadialCenter", "RadialCallout"}]},
  ChartStyle -> "SolarColors"] /. False -> True

enter image description here

Or, remove the annuli and disks from the callout lines:

GraphComputation`GraphPropertyChart[g, Automatic -> dc[[ordering]],
 ChartElementFunction -> None,
 ChartLabels -> {Placed[{dc[[ordering]], ordering}, {"RadialCenter", "RadialCallout"}]},
 ChartStyle -> "SolarColors"] /. False -> True /. _Disk:> {}

enter image description here

To order vertices by a property other than the default DegreeCentrality, say BetweennessCentrality, we use the desired ordering as the value of the option Automatic:

bc = BetweennessCentrality[g]; 
GraphComputation`GraphPropertyChart[g,
    Automatic -> Sort[bc], 
    ChartStyle -> "Rainbow", 
    ChartLabels -> {Placed[{Sort@bc, Ordering@bc}, 
      {"RadialCenter", "RadialCallout"}]}]  /. _Disk :> {}

enter image description here

$\endgroup$

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.