Group Abstract Group Abstract

Message Boards Message Boards

Make a hierarchy/organisational chart?

Posted 7 years ago
POSTED BY: Kjetil Thorsen
6 Replies

Instead of creating a new function fun, how about just using existing Wolfram Language functionality:

 Thread[Rule["CEO",{"VP1","VP2","VP3"}]]
POSTED BY: Seth Chandler
Posted 7 years ago

Thanks. Yes, this is better.

POSTED BY: Kjetil Thorsen

You might consider a different way of making this diagram. In your cases nested expression logic also works and fixes all your issues:

TreeForm[
    CEO[
       VP1[
         EMP1[
          EMP1,
          EMP2]],
       VP2[
         EMP2,
         EMP3],
       VP3],
DirectedEdges->True]

enter image description here

Another way is to switch to Graph and control which vertex is the root. You will have to explore numerous options Options[Graph] to make it look nicer so, for labels probably with VertexShapeFunction.

fun[a_, b_] := Map[a -> # &, b];
layer1 = fun[CEO, {VP1, VP2, VP3}];
layer2a = fun[VP1, {employee1}];
layer2b = fun[VP2, {employee2, employee3}];
layer2c = 
  fun[VP3, {employee4, employee5, employee6, employee7, employee8, 
    employee9}];
layer3a = fun[employee8, {employee10, employee11}];
layer3b = fun[employee9, {employee12}];
layer4 = fun[employee12, {employee13, employee14}];
Graph[Flatten[{layer1, layer2a, layer2b, layer2c, layer3a, layer3b, 
   layer4}], 
 GraphLayout -> {"LayeredEmbedding", "RootVertex" -> CEO, 
   "Orientation" -> Left}, GraphStyle -> "SimpleLink", 
 AspectRatio -> 1]

enter image description here

POSTED BY: Vitaliy Kaurov
Posted 7 years ago
POSTED BY: Kjetil Thorsen

Hi Kjetil,

maybe this serves as a first approximation:

fun[a_, b_] := Map[a -> # &, b];
layer1 = fun[CEO, {VP1, VP2, VP3}];
layer2a = fun[VP1, {employee1}];
layer2b = fun[VP2, {employee2, employee3}];
layer2c = fun[VP3, {employee4, employee5, employee6, employee7, employee8, employee9}];
layer3a = fun[employee8, {employee10, employee11}];
layer3b = fun[employee9, {employee12}];
layer4 = fun[employee12, {employee13, employee14}];
(* using strings is probably better than using symbols: *)
dept = Rule[ToString[#1], ToString[#2]] & @@@ Flatten[{layer1, layer2a, layer2b, layer2c, layer3a, layer3b, 
     layer4}];
(* explicit naming - identical names possible:  *)
vl = {"CEO" -> "John", "VP1" -> "John", Automatic};
Graph[dept, VertexLabels -> vl, ImageSize -> Full, GraphLayout -> "LayeredDigraphEmbedding"]

This gives:

enter image description here

Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 7 years ago

Thank you Henrik for the suggestion.

This is a good next step in what I wrote. I was hoping for something completely different and less involved as this ought to be a basic operation. Especially since Mathematica is (evolving to be) an article and presenter tool.

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