graphviz: Create new node with this same label

Piotr0123456 picture Piotr0123456 · May 14, 2012 · Viewed 10.2k times · Source

I'm starting working with graphviz and I have problem with creating new nodes with this same label. For example for word "sentence" I would like to create graph with 8 nodes: s -> e -> n -> t -> e -> n -> c -> e Now I'm receiving graph with only 5 nodes (one "e" instead of 3 and one "n" instead of 2). I need to create more nodes with this same label (value).

Example of my problem may be this image http://rdftwig.sourceforge.net/paper/diagrams/bfsdeep.png where there are 2 nodes with value "C", "E" and "D".

Is it possible? If it is possible how can I access in my example with word "sentence" first, second or third "e" node?

Answer

Maehler picture Maehler · May 14, 2012

You could define your nodes explicitly and set the label for them. Then each node has an unique id, but can have the same labels. Consider this example:

strict graph G {
    1 [label="A"];
    2 [label="B"];
    3 [label="B"];
    4 [label="A"];
    1 -- 2;
    2 -- 3;
    3 -- 4;
}

which will output (with dot):

Nodes with same labels