Plot data.tree, How to customize

210 views Asked by At

I would like to customize my data.tree. The problem is that I would need an arrow from each node to show me my "Salary" in order. It would be exactly the format you get when you type print(data.tree) .

To explain:

Chef <- Node$new("Chef")
Chef2 <- Chef$AddChild("Chef2")
Manager1 <- Chef2$AddChild("Manager1")
Manager2 <- Chef2$AddChild("Manager2")
Manager3 <- Chef2$AddChild("Manager3")
employee1 <- Manager1$AddChild("employee1")
employee2 <- Manager1$AddChild("employee2")
employee3 <- Manager2$AddChild("employee3")
employee4 <- Manager2$AddChild("employee4")
employee5 <- Manager2$AddChild("employee5")
employee6 <- Manager3$AddChild("employee6")
employee7 <- Manager3$AddChild("employee7")
employee8 <- Manager3$AddChild("employee8")

Salary <- c("100000", "50000", "25000", "25000", "3000", "90000", "20000", "1000", "10000", "5000", "1500", "5000", "3000")

Chef <- ToDataFrameTree(Chef, "pathString")
Chef <- as.data.frame(Chef)
Chef$Salary <- Salary
Chef <- as.Node(Chef)


print(Chef, "Salary")
plot(Chef)

It would be great if I can viusalize it so that it it looks like this:

print(Chef, "Salary")

However I only manage something like this...

plot

I know it's a bit complicated described, but if anyone can help, I would appreciate it.

1

There are 1 answers

0
Grasshopper_NZ On

As you tagged your question with diagrammer, one option is to use Mermaid.js.

1. Open Mermaid Live Editor

Mermaid allows even non-programmers to easily create detailed and diagrams through the Mermaid Live Editor.

2. Basic structure

In the </>code section, enter:

flowchart LR
   Chef --> Chef2
   Chef2 --> Manager1 & Manager2 & Manager3
   Manager1 -->   employee1 & employee2
   Manager2 -->   employee3 & employee4 & employee5
   Manager3 -->   employee6 & employee7 & employee8

3. Review the basic graph

You will see a graph on the right-hand side of the editor (as below).

enter image description here

4. Modify to get the desired graph

Add wage label to each person, clear the </>code section, and enter the new code below:

flowchart LR

subgraph A["100,000"]
direction LR
Chef
end

subgraph B["50,000"]
direction LR
Chef2
end

subgraph C["25,000"]
direction LR
Manager1
end

subgraph D["90,000"]
direction LR
Manager2
end

subgraph E["5,000"]
direction LR
Manager3
end

subgraph F["25,000"]
direction LR
employee1
end

subgraph G["3,000"]
direction LR
employee2
end

subgraph H["20,000"]
direction LR
employee3
end

subgraph I["1,000"]
direction LR
employee4
end

subgraph J["10,000"]
direction LR
employee5
end

subgraph K["15,000"]
direction LR
employee6
end

subgraph L["5,000"]
direction LR
employee7
end

subgraph M["3,000"]
direction LR
employee8
end

Chef --> Chef2
Chef2 --> Manager1 & Manager2 & Manager3
Manager1 -->   employee1 & employee2
Manager2 -->   employee3 & employee4 & employee5
Manager3 -->   employee6 & employee7 & employee8

You will see an updated graph on the right-hand side of the editor (as below). enter image description here

5. Download the preferred graph

If you are happy with it, choose the preferred format and download the graph.