=== UPDATE ===
Functionality and concept are updated and discussed here:
Orthogonal aka rectangular edge layout for Graph
=== OLDER ===
The main problem here I think is laying out edges along orthogonal lines. This can be addressed with splines. First define function that triples every element in the list to make a spline to pass sharply through the points.
mlls[l_] := Flatten[Transpose[Table[l, {i, 3}]], 1];
In the function below I'll define a special EdgeRenderingFunction
, a trick learned from @Yu-SungChang . Using LayeredGraphPlot
:
OrthoLayer[x_] := LayeredGraphPlot[x, VertexLabeling -> True,
PlotStyle -> Directive[Arrowheads[{{.02, .8}}], GrayLevel[.3]],
EdgeRenderingFunction -> (Arrow@
BezierCurve[
mlls[{First[#1], {(1 First[#1][[1]] + 2 Last[#1][[1]])/3,
First[#1][[2]]}, {(1 First[#1][[1]] + 2 Last[#1][[1]])/3,
Last[#1][[2]]}, Last[#1]}]] &)]
Now I will use data from HERE and test the function
OrthoLayer[g]
Or similarly using Graph
function:
OrthoLayer[x_] := Graph[x,
GraphLayout -> "LayeredDrawing",
VertexLabels -> "Name", VertexSize -> .1, VertexStyle -> Red,
EdgeStyle -> Directive[Arrowheads[{{.015, .8}}], GrayLevel[.3]],
EdgeShapeFunction -> (Arrow@
BezierCurve[
mlls[{First[#1], {(1 First[#1][[1]] + 2 Last[#1][[1]])/3,
First[#1][[2]]}, {(1 First[#1][[1]] + 2 Last[#1][[1]])/3,
Last[#1][[2]]}, Last[#1]}]] &),
PlotRange -> {{-.1, 4.4}, {-.1, 2.5}}]
OrthoLayer[g]
Using splines allows us to take advantage of various GraphLayout
settings and still keep orthogonal edges.
g = {"John" -> "plants", "lion" -> "John", "tiger" -> "John",
"tiger" -> "deer", "lion" -> "deer", "deer" -> "plants",
"mosquito" -> "lion", "frog" -> "mosquito", "mosquito" -> "tiger",
"John" -> "cow", "cow" -> "plants", "mosquito" -> "deer",
"mosquito" -> "John", "snake" -> "frog", "vulture" -> "snake"};
OrthoLayer[x_, st_] :=
Graph[x, GraphLayout -> st, VertexLabels -> "Name", VertexSize -> .3,
VertexStyle -> Red,
EdgeStyle -> Directive[Arrowheads[{{.015, .8}}], GrayLevel[.3]],
EdgeShapeFunction -> (Arrow@
BezierCurve[
mlls[{First[#1], {(1 First[#1][[1]] + 2 Last[#1][[1]])/3,
First[#1][[2]]}, {(1 First[#1][[1]] + 2 Last[#1][[1]])/3,
Last[#1][[2]]}, Last[#1]}]] &), PlotRange -> All,
PlotRangePadding -> .2]
OrthoLayer[g, #] & /@ {"CircularEmbedding", "LayeredDrawing",
"RandomEmbedding", "SpiralEmbedding", "SpringElectricalEmbedding",
"SpringEmbedding"}
Not perfect, but a start. Many things can be adjusted to customize specific data.
GridGraph
is probably what you want... $\endgroup$VertexCoordinates
) becomes not so trivial in this case. This is how I understand the question, but I agree it needs clarification. $\endgroup$