I have some simple hierarchical data (parent-child hierarchy) that I would like to visualize in R. I am currently using the R package "collapsibletree" but have not found a way to change the default depth to show the tree with, perhaps, 3 levels expanded. I know I can either show the full tree (collapsed = FALSE) or have it display fully collapsed (collapsed = TRUE) but have not found a way to specify the default depth. Any advice on this would be greatly appreciated.
Sample data and code included below.
dput:
structure(list(ParentNode = c(NA, "President", "President", "CFO",
"COO", "Operations SVP", "FP&A SVP", "FP&A VP", "FP&A Senior Analyst"
), Node = c("President", "COO", "CFO", "FP&A SVP", "Operations SVP",
"Operations VP", "FP&A VP", "FP&A Senior Analyst", "FP&A Associate"
)), class = "data.frame", row.names = c(NA, -9L))
| Node | ParentNode | ID | ParentID |
|---|---|---|---|
| President | 1 | ||
| COO | President | 2 | 1 |
| CFO | President | 3 | 1 |
| Accounting SVP | CFO | 4 | 3 |
| FP&A SVP | CFO | 5 | 3 |
| FP&A VP | FP&A SVP | 6 | 5 |
| Senior Analyst | FP&A VP | 7 | 6 |
| Senior Associate | FP&A VP | 8 | 6 |
| Associate | Senior Associate | 9 | 8 |
| Intern | Associate | 10 | 9 |
> library(collapsibleTree)
> Data1 <- read.csv(".....csv", na.strings ='', stringsAsFactors = FALSE)
> Data2 <- Data1[, c(2,1)]
> collapsibleTreeNetwork(Data2, collapsed = TRUE, inputId = 'node')

We don't have any reproducible data, so let's use the built-in dataset
warpbreaks, as used in thecollapsibleTreehelp file.By default, all nodes except the root node are collapsed:
If we set
collapsed = FALSEthen all nodes are expanded:If you want a different starting arrangement, then according to the help file, the
collapsedargument can be used as follows:The entry for
filltells us:So we want to show the next level of the tree after the default value, we need
collapsedto be a vector of 3FALSEfollowed by 55TRUE.In general, we can work out the correct nodes to collapse by passing this function:
This allows