Hi everybody,
I am trying to create a graph placing nodes in layers, order by its centrality. I have managed to group them using ranks and order them using invisible rank nodes and edges. I also managed to add two “Y axis”. This is the code (Graphviz Online) and resulting graph
[dot verbose=true]
digraph prof {
graph[splines=yes];
rankdir="TB";
layout="dot";
node [fontname="Helvetica", fontcolor="white"];
edge [style=bold, color="#888"]
fontsize=12;
// =============================
// Centrality Y axis
// =============================
subgraph cluster_legend {
layout="dot";
label="Centralidad";
fontname="Helvetica";
color=transparent;
penwidth=2;
subgraph cluster_legend_nodes{
label="";
peripheries=0;
node [fontname="Helvetica", fontcolor="black", penwidth=3];
scale_0 [label="0", height=.8, color=transparent, shape=square];
scale_05 [style=invisible];
scale_1 [label="2", height=.8, color=transparent, shape=square];
scale_15 [style=invisible];
scale_2 [label="4", height=.8, color=transparent, shape=square];
scale_25 [style=invisible];
scale_3 [label="6", height=.8, color=transparent, shape=square];
scale_35 [style=invisible];
scale_4 [label="8", height=.8, color=transparent, shape=square];
scale_4 -> scale_35 -> scale_3 [style=line, arrowhead=none];
scale_3 -> scale_25 -> scale_2 [style=line, arrowhead=none];
scale_2 -> scale_15 -> scale_1 [style=line, arrowhead=none];
scale_1 -> scale_05 -> scale_0 [style=line, arrowhead=none];
}
}
// Invisible nodes to control order
rank2 [style=invisible, group=2];
rank3 [style=invisible, group=3];
rank4 [style=invisible, group=4];
rank5 [style=invisible, group=5];
rank6 [style=invisible, group=6];
rank7 [style=invisible, group=7];
rank8 [style=invisible, group=8];
rank9 [style=invisible, group=9];
rank10 [style=invisible, group=10];
// Invisible edges to maintain vertical order and distance
rank2 -> rank3 [style=invis];
rank3 -> rank4 [style=invis];
rank4 -> rank5 [style=invis];
rank5 -> rank6 [style=invis];
rank6 -> rank7 [style=invis];
rank7 -> rank8 [style=invis];
rank8 -> rank9 [style=invis];
rank9 -> rank10 [style=invis];
// =============================
// Real nodes definition
// =============================
// Objetivos
1 [label="OB1", style=filled, fillcolor="red", color="red", penwidth=4, shape=square, group=7];
2 [label="OB2", style=filled, fillcolor="red", color="red", penwidth=4, shape=square, group=2];
3 [label="OB3", style=filled, fillcolor="red", color="red", penwidth=4, shape=square, group=5];
4 [label="OB4", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=square, group=6];
5 [label="OB5", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=square, group=5];
6 [label="OB6", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=square, group=6];
7 [label="OB7", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=5];
8 [label="OB8", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=8];
9 [label="OB9", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=8];
10 [label="OB10", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=6];
// Actuaciones
11 [label="AC1", style=filled, fillcolor="red", color="red", penwidth=4, shape=circle, group=5];
12 [label="AC2", style=filled, fillcolor="red", color="red", penwidth=4, shape=circle, group=7];
13 [label="AC3", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=6];
14 [label="AC4", style=filled, fillcolor="red", color="red", penwidth=4, shape=circle, group=7];
15 [label="AC5", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=9];
16 [label="AC6", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=6];
17 [label="AC7", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=8];
18 [label="AC8", style=filled, fillcolor="green", color="green", penwidth=4, shape=circle, group=7];
19 [label="AC9", style=filled, fillcolor="green", color="green", penwidth=4, shape=circle, group=9];
20 [label="AC10", style=filled, fillcolor="green", color="green", penwidth=4, shape=circle, group=7];
{rank=min;rank2;2}
{rank=same;rank5;3;5;7;11}
{rank=same;rank6;4;6;10;13;16}
{rank=same;rank7;1;12;14;18;20}
{rank=same;rank8;8;9;17}
{rank=same;rank9;15;19}
// =============================
// Links
// =============================
1 -> 2 ;
1 -> 5 ;
1 -> 11 ;
2 -> 1 ;
2 -> 5 ;
2 -> 12 ;
2 -> 13 ;
5 -> 1 ;
5 -> 3 ;
3 -> 5 ;
5 -> 15 ;
3 -> 2 ;
3 -> 7 ;
3 -> 13 ;
7 -> 10 ;
7 -> 17 ;
4 -> 3 ;
4 -> 9 ;
4 -> 14 ;
4 -> 11 ;
9 -> 19 ;
6 -> 7 ;
6 -> 2 ;
6 -> 16 ;
10 -> 20;
8 -> 10 ;
8 -> 18 ;
11 -> 10;
11 -> 16;
13 -> 5 ;
13 -> 12;
14 -> 7 ;
14 -> 11;
16 -> 2 ;
16 -> 20;
17 -> 12;
18 -> 2 ;
18 -> 6 ;
20 -> 2 ;
// =============================
// Second centrality Y axis
// =============================
subgraph cluster_legend_bis {
layout="dot";
label="Centralidad";
fontname="Helvetica";
color=transparent;
penwidth=2;
subgraph cluster_legend_nodes_bis{
label="";
peripheries=0;
node [fontname="Helvetica", fontcolor="black", penwidth=3];
scale_0_bis [label="0", height=.8, color=transparent, shape=square];
scale_05_bis [style=invisible];
scale_1_bis [label="2", height=.8, color=transparent, shape=square];
scale_15_bis [style=invisible];
scale_2_bis [label="4", height=.8, color=transparent, shape=square];
scale_25_bis [style=invisible];
scale_3_bis [label="6", height=.8, color=transparent, shape=square];
scale_35_bis [style=invisible];
scale_4_bis [label="8", height=.8, color=transparent, shape=square];
scale_4_bis -> scale_35_bis -> scale_3_bis [style=line, arrowhead=none];
scale_3_bis -> scale_25_bis -> scale_2_bis [style=line, arrowhead=none];
scale_2_bis -> scale_15_bis -> scale_1_bis [style=line, arrowhead=none];
scale_1_bis -> scale_05_bis -> scale_0_bis [style=line, arrowhead=none];
}
}
}
[/dot]
Now I want to add horizontal background stripes or lines to separate each centrality level, going from the left axis to the right axis. I have tried to create subgraphs for every level, adding the corresponding nodes, but it does not work well.
Do you have any idea?
Thanks in advance.