views:

85

answers:

2

While I'm waiting for the sorting to finish, I would like to adjust a part of Mathematica graph I'm working on. The problem is that nodes are on top of edges, I wonder if there is a way to reverse that. In the image you can see that arrows are not showing proper...

I'm doing a GraphPlot[] with custom VertexRenderingFunction and EdgeRenderingFunction paramaters. It looks something like this:

Where are the arrows? Can you see them? Did you take my arrows?

As you can see, it would be as they say cool if the arrows were on top of the nodes. Is there an easy way to hax it in?

+2  A: 

I don't know if there is a way to do this directly with GraphPlot options or not but you could manipulate the Graphics object produced by GraphPlot directly. For example, here's a graph whose features are similar to yours.

bg = GraphPlot[Table[i -> Mod[3 i + 1, 9],
  {i, 0, 8}], DirectedEdges -> True,
  VertexRenderingFunction -> (
  {{White, Disk[#, 0.15]}, Circle[#, 0.15]} &),
  EdgeRenderingFunction -> (Arrow[#1] &)]

You can examine the structure of the Graphics primitives and directives as follows:

  bg // InputForm

You can see that the arrows are placed down before the vertices. Simply reverse this as follows.

  MapAt[Reverse, bg, {1, 1}]

Of course, your Graphics object will likely have a different structure.

Mark McClure

Mark McClure
That looks great, I'll try that and report back!
Gleno
+2  A: 

Mark's answer does exactly what you asked for -- and you could write your own function that automates the Reverse.

A less direct solution might be to just draw the arrow heads back from the end a little:

GraphPlot[Table[i -> Mod[3 i + 1, 9], {i, 0, 8}], 
 VertexRenderingFunction -> ({{White, Disk[#, 0.15]}, 
     Circle[#, 0.15]} &), DirectedEdges -> True, 
 EdgeRenderingFunction -> ({Arrowheads[{{.05, .8}}], Red, 
     Arrow[#]} &)]

This would also reduce the congestion at the nodes.

Simon
Thanks, this worked... after a while. :)
Gleno