# Use layout of directed graph in an undirected graph

I'm fond of the default vertex and edge layout for a directed graph:

edges = {1 -> 2, 0 -> 2, 0 -> 4, 0 -> 1, 0 -> 3, 2 -> 4, 1 -> 2,
2 -> 3, 1 -> 4, 3 -> 4, 1 -> 3, 0 -> 1, 1 -> 2, 1 -> 3, 1 -> 4,
2 -> 3, 2 -> 4, 3 -> 4, 0 -> 1, 0 -> 1, 0 -> 2, 1 -> 2};

Graph[edges]


I want to use this layout for an "equivalent" undirected graph, or at least one with no arrows drawn. The default layout however is different:

Graph[UndirectedEdge @@@ edges]


There is no GraphLayout option (in v11.2) that yields the same layout, possibly due to the undirected edges being weighted different than directed ones in the layout algorithms. Can I force Mathematica to use the directed graphs embedding? I only need the ultimate Graphics from Show[graph].

• This has nothing to do with weights. The layout you want is computed based on edge directions. It is clear that all arrows are pointing from higher layers to lower ones. It is simply not possible for undirected graphs. You can assign directions to your edges and use the directed layout, then transfer the vertex coordinates to the undirected version again. But the result will depend on how you assigned those directions. – Szabolcs Dec 21 '20 at 20:41
• Also, if I saw such a layout in a publication, I'd assume that the arrowheads went missing by accident and this is still a directed graph. Not a good idea to try to force such a layout for undirected graph, as it implies edge directions. You'll just confuse your readers. – Szabolcs Dec 21 '20 at 20:42
• I suspected I could extract the positions and transfer them, but didn't know quite how to do it. And hey, confusing my readers is entirely up to me ;) – Anti Earth Dec 21 '20 at 21:00
• If you have the undirected graph g already, you can do something like DirectedGraph[g, "Acyclic", GraphLayout -> "LayeredDigraphEmbedding", EdgeShapeFunction -> "Line"] – Szabolcs Dec 21 '20 at 21:45

Show[Graph @ edges] /. Arrow[b_BezierCurve, ___] :> b

Graph[edges, EdgeShapeFunction -> "Line"]