5
$\begingroup$

I have a network graph in which the edge color is proportional to the edge weight. Edges with a low weight value appear almost white. I would like the edges to be drawn such that those with a higher weight are drawn last. This will minimize light edges crossing over darker ones, and make the graph look nicer.

As far as I can tell, there is no way to specify the order that edges are drawn. The only thing that changes the order that edges are drawn in is the vertex order. Here is a toy example (without weighted edges to make it simple):

compGr = CompleteGraph[5];
cV = VertexList[compGr];
cE = EdgeList[compGr];

cEcolor = 
  Transpose[{cE, {Gray, Lighter[Yellow, 0.6], Black, Gray, Gray, 
     Darker[Green, 0.5], Darker[Red, 0.5], Gray, Lighter[Blue, 0.95], 
     Gray}}];
eProp = (#[[1]] -> {EdgeStyle ->  {#[[2]], Thickness[0.02], 
         Opacity[1]}}) & /@ cEcolor;

Grid[{{"Base", "Reversed Vertex Order", 
   "Reverse Edge Order"}, {compGr1 = 
    Graph[cV, cE, Properties -> eProp],
   compGr1 = Graph[Reverse[cV], cE, Properties -> eProp],
   compGr1 = Graph[cV, Reverse[cE], Properties -> eProp]}}]

Which gives: Note the yellow and light blue lines as the cross the red, black and green edges.

Ideally, I want to plot edges with the lightest (lowest edge weight) edges appearing underneath the darker edges (highest edge weight). I have tried specifying the edges and their properties sorted in the order to be drawn without success. Since my vertices have multiple edges, with varying edge weights, sorting the vertices would not give the proper order.

The ideal solution would let me specify the order in which edges are drawn.

$\endgroup$
7
$\begingroup$

You can use GraphLayout -> {"RenderingOrder" -> ...} option:

Graph[cV, cE, Properties -> eProp, 
 GraphLayout -> {"RenderingOrder" -> 
    SortBy[cEcolor, ColorDistance[White, ColorConvert[#[[2]], "Grayscale"]] &][[All, 1]]}]
$\endgroup$
  • 1
    $\begingroup$ Thank-you! Works perfectly. I missed this in the documentation. I wish Wolfram would make some of the options searchable in the help option. "RenderingOrder" is hard to find. $\endgroup$ – GraphMan Sep 7 '17 at 22:48

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.