2
$\begingroup$

I have simple graph I am trying to explore to see how I can control various properties of a TreeGraph. For example, within the following function call, I have found out how to color individual vertices, control their size, and controlled the vertex shape and size:

t2 = TreeGraph[{Style[1, Green], Style[2, Blue], Style[3, Yellow], 
       Style[4, Orange]}, {1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 
         1 \[DirectedEdge] 4}, 
       VertexCoordinates -> {{.7, .5}, {0, 0}, {.6, 0}, {2.5, 0}}, 
       VertexLabelStyle -> 18, VertexLabels -> Placed["Name", "Center"], 
       VertexShapeFunction -> {1 -> "Square", 2 -> "Triangle", 
           3 -> "Circle", 4 -> "Pentagon"}, 
       VertexSize -> {1 -> 0.2, 2 -> 0.5, 3 -> 0.3, 4 -> 0.1}]

However, I have yet to figure out how to: 1) color each individual edge with a color of my choice, 2) control the thickness for each individual edge,

  1. color each individual edge with a color of my choice
  2. control the thickness of each individual edge
  3. control the type, size, and position of the arrowhead, so that it is not obscured when the vertices are made large

It seems that in Ver. 12, EdgeStyle has been depreciated and its functionality is said to be replaced by EdgeShapeFunction.

However, when I try to include the following option:

EdgeShapeFunction -> {{{1 \[DirectedEdge] 2}, Blue}, {{1 \[DirectedEdge] 3}, 
  Yellow}, {{1 \[DirectedEdge] 4}, Orange}} 

the system does not return a graphic, but rather a symbolic "System`Graph", with a vertex count of 4, and edge count of 3, identifying the graph as a direct graph, but strangely stating that the Connected Graph: [False] and Acyclic graph: [False], when in fact both properties are true for this simple tree.

Likewise, specifying the option:

 VertexLabels-> Placed["Name","Center"]

among those already present, butno VertexLabels appear centered within the vertex, as expected, despite its inclusion.

How does one specify the EdgeShapeFunction to gain this additional functionality and added control in version 12?

The examples given in the documentation for EdgeShapeFunction seems to need a few more comprehensive examples for low level property control.

$\endgroup$
  • 1
    $\begingroup$ " EdgeStyle has been depreciated and its functionality is said to be replaced by EdgeShapeFunction." Why would you think that? This is not true. $\endgroup$ – Szabolcs May 27 at 8:08
  • $\begingroup$ Funny, on Version 12, when I made the change the first time for EdgeStyle as kglr suggested it worked and I was able to control the edge properties. However, when I try it again at a later time, EdgeStyle is placed in Red and the Edges are not modified as requested. The code executes without any errors being flagged, but the code as KGLR now does not change the edge style as requested. Any ideas? Vers. 12, windows 64 bit. $\endgroup$ – Stuart Poss May 29 at 15:27
  • $\begingroup$ Did you load any packages? Combinatorica? (Don't do that, Combinatorica is deprecated and will override Graph) You'd need to show me a complete example (one-liner please) to trigger this before I can tell you why it happens. $\endgroup$ – Szabolcs May 29 at 15:37
1
$\begingroup$
  1. Use VertexLabels -> Placed["Name", Center] to place the labels at the centers.
  2. Add the option PerformanceGoal->"Quality" to have the arrows automatically adjusted to make the arrow heads for different vertex sizes.
  3. Use the option EdgeStyle to style edges as you like.

 TreeGraph[{Style[1, Green], Style[2, Blue], Style[3, Yellow], 
         Style[4, Orange]}, {1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 
           1 \[DirectedEdge] 4}, 
        VertexCoordinates -> {{.7, .5}, {0, 0}, {.6, 0}, {2.5, 0}}, 
        VertexLabelStyle -> 18, 
        VertexLabels -> Placed["Name", Center], 
        PerformanceGoal->"Quality",
        VertexShapeFunction -> {1 -> "Square", 2 -> "Triangle", 
              3 -> "Circle", 4 -> "Pentagon"}, 
        VertexSize -> {1 -> 0.6, 2 -> 0.5, 3 -> 0.4, 4 -> 0.9}, 
        EdgeStyle->{(1 \[DirectedEdge] 2) -> Directive[Thick, Blue], 
        (1 \[DirectedEdge] 3) -> Purple, 
        (1 \[DirectedEdge] 2) -> Directive[Dashed, Thickness[.005], Orange]}]

enter image description here

Alternatively, you can remove VertexLabels -> Placed["Name", Center] and wrap the vertices with Labeled using

{Style[1, Green], Style[2, Blue], Style[3, Yellow], 
         Style[4, Orange]}/. Style[a_,s_]:> Style[Labeled[a,a,Center],s]

as the first argument of TreeGraph to get the same picture.

Note: Modified OP's code to make the vertex sizes larger.

$\endgroup$

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.