Message Boards Message Boards

Use TreePlot to create organization or flow charts?

Posted 7 years ago

Hi everyone, I am wondering whether there is a way to use TreePlot to create organization or flow charts. Here is a default tree plot from the Wolfram documentation.

TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, 3 -> 8, 4 -> 5, 
  7 -> 8}, Top, VertexLabeling -> True]

As intended, the branches radiate out from the centre of each vertex. In an organization or flow chart, the branches come out of each vertex at right angles to the vertex (example attached and hopefully embedded in this post).

Example of a flow chart

Any thoughts?

Greg

Attachments:
POSTED BY: Gregory Lypny
9 Replies
Posted 7 years ago

Thank you so much. That worked.

POSTED BY: Null Null
Posted 7 years ago

Hi, @Sander Huisman. This is fantastic. I'd like to add arrows using this code. I tried adding DirectedEdges->True with no avail. Any suggestions? Thanks!

POSTED BY: Null Null

That is because my own EdgeRenderingFunction ignores this DirectedEdges option. I'm fairly certain that if you change Line to Arrow (2 times) it should work...

POSTED BY: Sander Huisman
Posted 7 years ago

Hi Sander,

This is so cool. Just what the doctor ordered. It will take me a little time to study and understand your edge function, but it looks like the FreeQ[...,0.] condition ensures that the branches travel at right angles to the vertices and the division by 2 draws the horizontal lines. I never would have thought of this.

Thanks once again,

Greg

POSTED BY: Gregory Lypny

Strictly the FreeQ condition is not necessary, it will just save a bit of memory... visually it will look the same...

POSTED BY: Sander Huisman
Posted 7 years ago

I don't understand because I did upload a PNG. In any case, if you do a Google search for organization chart and check out the images, it will be clear.

Thanks again,

Gregory

POSTED BY: Gregory Lypny

Aah ok I see it now:

ClearAll[func]
func[{ri_,rj_},___]:=If[FreeQ[ri-rj,0.],Line[{ri,{ri[[1]],(ri[[2]]+rj[[2]])/2},{rj[[1]],(ri[[2]]+rj[[2]])/2},rj}],Line[{ri,rj}]]
TreePlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8},Top,VertexLabeling->True,EdgeRenderingFunction->func]

enter image description here

POSTED BY: Sander Huisman
Posted 7 years ago

Hi Sander,

The image is also in an attachment. Thanks for your suggestion. It's pretty darn close. I'm going to study your code.

Regards,

Gregory

POSTED BY: Gregory Lypny

I can't see your image, but I guess you want something like:

ClearAll[func]
func[{ri_,rj_},___]:=If[FreeQ[ri-rj,0.], Line[{ri,{rj[[1]],ri[[2]]},rj}],Line[{ri,rj}]]
TreePlot[{1->4,1->6,1->8,2->6,3->8,4->5,7->8},Top,VertexLabeling->True,EdgeRenderingFunction->func]

enter image description here

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract