I was trying to recreate following graphviz graph with tikz (from https://graphs.grevian.org/example)
graph {
rankdir=LR;
a -- { b c d }; b -- { c e }; c -- { e f }; d -- { f g }; e -- h;
f -- { h i j g }; g -- k; h -- { o l }; i -- { l m j }; j -- { m n k };
k -- { n r }; l -- { o m }; m -- { o p n }; n -- { q r };
o -- { s p }; p -- { s t q }; q -- { t r }; r -- t; s -- z; t -- z;
{ rank=same; b, c, d }
{ rank=same; e, f, g }
{ rank=same; h, i, j, k }
{ rank=same; l, m, n }
{ rank=same; o, p, q, r }
{ rank=same; s, t }
}
To replicate the setting rankdir=LR;
I have followed the advice from Rotate tikz "Layered Layout" and have added grow=right, components go down left aligned
:
%! TEX program = lualatex
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs,graphdrawing,shapes}
\usegdlibrary{layered}
\begin{document}
\tikz \graph [layered layout,
nodes={ellipse, minimum width=25pt, draw},
% https://tex.stackexchange.com/q/390417/rotate-tikz-layered-layout
grow=right, components go down left aligned
] {
{ [same layer] b, c, d };
{ [same layer] e, f, g };
{ [same layer] h, i, j, k };
{ [same layer] l, m, n };
{ [same layer] o, p, q, r };
{ [same layer] s, t };
a[nudge left=25mm] -- { b, c, d }; b -- { c, e };c -- { e, f };
d -- { f, g }; e -- h; f[nudge down=10mm] -- { h, i, j, g };
g[nudge down=10mm] -- k; h --[bend left=-30] o; h -- l;
i -- { l, m, j }; j -- { m, n, k }; k -- { n, r }; l[nudge up=10mm] -- { o, m };
m[nudge up=10mm] -- { o, p, n }; n -- { q, r }; o -- { s, p }; p -- { s, t, q };
q -- { t, r }; r -- t; s -- z; t -- z;
};
\end{document}
I have removed unnecessary edge crossings by 'nudging' node a
to the left. To fill the empty space left by the moved node a
, I have moved g
and f
downwards. Also I had to adjust m
and l
upwards and bend the edge h--o
downwards.
Without these modifications the graph looks like
In particular the edge h--o
is completely misleading.
Does anyone know how to recreate the graphviz result, i.e. orient the layered graph horizontally (in contrast to the default) and avoid so many manual adjustments?
UPDATE
placing a
on an own layer already fixed nudging a
, f
and g
:
{ [same layer] a };
The remaining problem is apparently the crossing minimization algorithm which does not know the 'easy' solution to move m
and l
up and add the kink into the other direction:
Note: answer by marmot suggests to add those edges manually which connect nodes of two different layers with at least one additional layer between them. Maybe this could be a rule of thumb for other graphs as well.