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]

enter image description here

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

How can this be achieved?

  • $\begingroup$ 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. $\endgroup$
    – Szabolcs
    Commented Jan 20, 2013 at 19:28

2 Answers 2


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]

enter image description here

  • $\begingroup$ 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. $\endgroup$
    – Jens
    Commented Jan 20, 2013 at 22:39
  • $\begingroup$ @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. $\endgroup$ Commented Jan 21, 2013 at 0:00
  • $\begingroup$ 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? $\endgroup$
    – user10853
    Commented Jun 6, 2014 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:

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.