For LayeredGraphPlot how to change the default yellow color?


produces the vertex label in yellow box with yellow border. I want to change the color to gray box with gray border.

  • $\begingroup$ You can also use Graph[..., GraphLayout -> "LayeredEmbedding"]. $\endgroup$ – Szabolcs Sep 28 '15 at 14:06
LayeredGraphPlot[{"abc" -> "18734523", "abc" -> "def"},
 VertexLabeling -> True,
 VertexRenderingFunction -> ({
     Text[Framed[Style[#2, 18, Black], 
       Background -> LightGray], #1]} &),
 EdgeRenderingFunction -> ({Purple, Line[#1], Arrowheads[{0, .1}], 
     Arrow[#1, {0, .5}]} &)]

Here, Line[#1] takes the arguments from LayeredGraphPlot representing the beginning and end vertexes in question; Arrowheads[{0, .1}] says make the "tail" arrowhead of size zero (i.e., don't render it) and the "head" arrowhead of (scaled) size .1; and Arrow[#1, {0, .5}] makes an arrow with the same beginning and end points of the Line but sets the ends back $0$ from the starting vertex and (scaled) 0.5 of its length back from the target or end vertex.

enter image description here

  • $\begingroup$ Thank you David, but increasing the length of vertex text makes it go outside the box. Also you are replacing the default box and not changing its properties. The default box changes its size with the text. $\endgroup$ – user13892 Sep 28 '15 at 13:58
  • $\begingroup$ Thank you David, I will accept your answer but please can you also add to the code how to change the color of the arrows as well. $\endgroup$ – user13892 Sep 28 '15 at 14:36
  • $\begingroup$ Hi David, Sometimes the arrowhead gets overlapped under the vertex box, can you please make the arrowhead in the middle of the line like it was in the default. $\endgroup$ – user13892 Sep 28 '15 at 15:30
  • $\begingroup$ @user13892: Acceptable now? $\endgroup$ – David G. Stork Sep 28 '15 at 16:39
  • $\begingroup$ Just a last thing, what does 0, 1, 0, 0.5 means in the code?? {Purple, Line[#1], Arrowheads[{0, .1}], Arrow[#1, {0, .5}]} $\endgroup$ – user13892 Sep 28 '15 at 16:41
Block[{RGBColor}, RGBColor[1, 1, 0.8] = LightGray; 
 RGBColor[0.94, 0.85, 0.36] = Gray; RGBColor[0.5, 0., 0.] = Purple; 
 LayeredGraphPlot[{"abc" -> "123456789", "abc" -> "def"}, 
  VertexLabeling -> True, PlotStyle->Directive[FontSize->24, Arrowheads[{{0.1, 0.63}}]]]]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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