# TreePlot, VertexRenderingFunction and stretched vertices issue

Bug introduced in 9.0.1 or earlier and persisting through 11.0.1 or later

Recently I found the following TreePlot issue. For simplicity, I took an example from Mathematica Tree Drawing Tutorial and set TreePlot orientation to Left:

TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 7 -> 9}, Left,
VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
Black, Text[#2, #1]} &)]

But when I specified the root node to 5 (which differs from an automatically selected root node 4), I recieved an image with stretched verticies:

TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 7 -> 9}, Left, 5,
VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
Black, Text[#2, #1]} &)]

Is there a generic solution to this problem? Thanks.

It seems that there is a bug in how TreePlot handles its default AspectRatio -> Automatic option:

tp = TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8,
7 -> 9}, Left, 5,
VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
Black, Text[#2, #1]} &), AspectRatio -> Automatic]
Options[tp, AspectRatio]

{AspectRatio -> 0.632456}

One workaround is to reset this option to Automatic again using Show:

Show[TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8,
7 -> 9}, Left, 5,
VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
Black, Text[#2, #1]} &)], AspectRatio -> Automatic]

The reason why the form of a disk is affected by AspectRatio is that you specify the disk radius in the scale of intrinsic coordinate system of the Graphics object:

Row[Graphics[Disk[{0, 0}, 1], Frame -> True, ImageSize -> 150,
AspectRatio -> #] & /@ {1, .5}]

If you specify the disk radii via Offset (in printer's points) the form of the disk will never be affected by AspectRatio:

TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8,
7 -> 9}, Left, 5,
VertexRenderingFunction -> ({EdgeForm[Black], Yellow,
Disk[#1, Offset[{20, 20}]], Black, Text[#2, #1]} &)]

As suggested in the comments, it is easier to adjust the disk radius if one specify it in the form Offset[r {1,1}] where r is the radius in printer's points.

• More accurate to say radius will not be stretched when the argument is a list of the form {r, r} and best to specify it with r {1, 1}, which makes it easier to adjust. Commented May 1, 2014 at 3:55
• Thanks, I have edited my answer accordingly. Commented May 1, 2014 at 4:13
• Good catch. +1.
– ciao
Commented May 1, 2014 at 7:14
TreePlot[{1 -> 4, 1 -> 5, 2 -> 8, 3 -> 4, 4 -> 8, 6 -> 8, 7 -> 8, 7 -> 9},
Left, 5, VertexRenderingFunction -> ({EdgeForm[Black], Yellow, Disk[#1, 0.2],
Black, Text[#2, #1]} &), AspectRatio -> .5]