# LayeredGraphPlot: two instances of the same label

What I'd like to do is to have the same label more than once in the plot. I.e. I do not want the edges to direct toward the first instance of that label! For example:

LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 3 -> 2}, VertexLabeling -> True]


I want 3 -> 2 (a new 2)!

How can this be achieved?

-
Welcome to Mathematica.SE! I edited your question a little bit to make it more readable. You can click the edit link above to see how you can do that yourself in the future. Regarding tags, please do not create new tags unless absolutely necessary. Try to find the best matching existing ones. –  Szabolcs Jan 20 '13 at 19:28

Latest graph functionality works as well. You could define the graph structure you need :

g = Graph[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 3 -> 5},
GraphLayout -> "LayeredDigraphEmbedding", VertexLabels -> "Name"];


and then relabel the part you need to be different:

SetProperty[{g, 5}, VertexLabels -> 2]


-
However, this doesn't return a Graphics object as does LayeredGraphPlot. And of course the styling options are different for Graph, so it will take a bit more work to make this a drop-in replacement. –  Jens Jan 20 '13 at 22:39
@Jens I do not think he cared for some specific styling (besides layout which is reproduced). I think the fact that this is a Graph, not Graphics is an advantage. Aside all computational advantages - you can turn Graph into Graphics via right click menu, but you cannot do the opposite. –  Vitaliy Kaurov Jan 21 '13 at 0:00
It's been over a year but thanks :) What If I want to do the same for words & boolean to create a flow map? Is that productive or do you suggest a specific software or Web application? –  user10853 Jun 6 '14 at 12:34

You have to identify the vertices uniquely, so I would call the second instance of 2 by the name 5 instead. But you can label them differently using this:

Clear[label];
label[5] = 2;

LayeredGraphPlot[{1 -> 2, 1 -> 3, 2 -> 3, 1 -> 4, 2 -> 4, 3 -> 5},
VertexLabeling -> True,
VertexRenderingFunction ->
Function[{p, l},
Text[Framed[If[ValueQ[label[l]], label[l], l],
Background -> RGBColor[1, 1, 0.8],
FrameStyle -> RGBColor[0.94, 0.85, 0.36]], p]]]


The VertexRenderingFunction option contains the same style as the default vertex labels, but instead of the vertex number supplied to it as the second argument l, it outputs the value of label[l]. The latter can be defined for any vertex number that you want to appear with a different label. If label[x] isn't defined, then ValueQ returns False and the label is displayed in the default form as x.

-
How about label[n_] := n; label[5] = 2 for simpler code? –  Szabolcs Jan 20 '13 at 19:29
@Szabolcs Sure, that works too. My rationale was to move the "default" state completely into the rendering function. –  Jens Jan 20 '13 at 19:33