4
$\begingroup$

I use the following code plot a binary tree and wants to change an edge to double arrow.

g = TreeGraph[{11 -> 23, 11 -> 24, 23 -> 40, 23 -> 39, 24 -> 30, 24 -> 50, 40 -> 55, 40 -> 45}, VertexShapeFunction -> ({EdgeForm[White], RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.2], White, Text[#2, #1]} &)] 

This plots the tree well. My question is how do I change a single edge to a double arrow, as illustrated below? It looks EdgeShapeFunction can do this, and I have tried the following without success. Thank you.

SetProperty[{g, 11 -> 23}, EdgeShapeFunction -> ("DoubleArrowheads")] 

enter image description here


I also have tried

SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{-.05, .05}]}] 

However, the arrows overlap with the vertex.

enter image description here

BTW, anyone knows how to chnage the font size in tree graph?

$\endgroup$
3
  • 1
    $\begingroup$ Use the option EdgeStyle -> {(11 -> 23) -> Arrowheads[{-.05, .05}]},? $\endgroup$ Commented Nov 16, 2015 at 13:43
  • 1
    $\begingroup$ ... or use SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{-.05, .05}]}]. $\endgroup$ Commented Nov 16, 2015 at 13:44
  • $\begingroup$ or SetProperty[{g, (11 -> 23)}, {EdgeStyle -> {Arrowheads[{-.05, .05}]}, PerformanceGoal -> "Quality"}] $\endgroup$ Commented Nov 16, 2015 at 17:44

1 Answer 1

3
$\begingroup$

You could use

SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{{-.05, .2}, {.05, .8}}]}] 

but since the offset is scaled relative to the line length, it's not possible in general to point the edge of the disk:

enter image description here

You can create custom EdgeShapeFunction to replace automatic:

arrow[pts : {p1_, p2_}, offset_, arrowheads_: {}] := With[{m = Mean[pts], w = Normalize[p2 - p1], n = Norm[p1 - p2]/2}, {Arrowheads@arrowheads, Arrow@{m - (n - offset) w, m + (n - offset) w}}]; g = TreeGraph[{11 -> 23, 11 -> 24, 23 -> 40, 23 -> 39, 24 -> 30, 24 -> 50, 40 -> 55, 40 -> 45}, EdgeShapeFunction -> (arrow[#, .2] &), VertexShapeFunction -> ({EdgeForm[White], RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.2], White, Text[#2, #1]} &) ] 

and

SetProperty[{g, (11 -> 23)}, EdgeShapeFunction -> (arrow[#, .2, {-.05, .05}] &)] 

enter image description here

$\endgroup$
1
  • $\begingroup$ I'm curious why I had to sue EdgeShapeFunction -> (arrow[#, .2] &), for g. If it is automatic, SetProperty results in single arrowhead added to every other edge... $\endgroup$ Commented Nov 16, 2015 at 16:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.