1

I am trying to create a collapsibletree object using the library(collapsibleTree) and library(dplyr) packages. Following this example, I tried to assign colors to my tree but I am not getting anything.

A few rows of the dataframe are provided below. the Failure column is categorical and has three options of c("Bar fracture", "Bar pullout", "Coupler failure"). I have created a new column named Color and assigned a value of 1 to each row that indicated the Failure type is Bar fracture and 0 to each row that says otherwise (the two other categories).

> dput(Mostafa[1:27,])
structure(list(`Coupler Type` = c("Headed Bar Coupler", "Headed Bar Coupler", 
"Headed Bar Coupler", "Headed Bar Coupler", "Headed Bar Coupler", 
"Headed Bar Coupler", "Headed Bar Coupler", "Headed Bar Coupler", 
"Headed Bar Coupler", "Grouted Sleeve Coupler", "Grouted Sleeve Coupler", 
"Grouted Sleeve Coupler", "Grouted Sleeve Coupler", "Grouted Sleeve Coupler", 
"Grouted Sleeve Coupler", "Grouted Sleeve Coupler", "Grouted Sleeve Coupler", 
"Grouted Sleeve Coupler", "Grouted Sleeve Coupler", "Grouted Sleeve Coupler",
"Grouted Sleeve Coupler", "Grouted Sleeve Coupler", "Grouted Sleeve Coupler", 
"Grouted Sleeve Coupler", "Grouted Sleeve Coupler", "Grouted Sleeve Coupler", 
"Grouted Sleeve Coupler"), `Coupler Manufacturer` = c("Headed Reinforcement Corp.", 
"Headed Reinforcement Corp.", "Headed Reinforcement Corp.", "Headed Reinforcement Corp.", 
"Headed Reinforcement Corp.", "Headed Reinforcement Corp.", "Headed Reinforcement Corp.", 
"Headed Reinforcement Corp.", "Headed Reinforcement Corp.", "Dayton Superior", 
"Dayton Superior", "Dayton Superior", "Dayton Superior", "Dayton Superior", 
"Dayton Superior", "Dayton Superior", "Dayton Superior", "Dayton Superior", 
"Splice Sleeve North America", "Splice Sleeve North America", 
"Splice Sleeve North America", "Splice Sleeve North America", 
"Splice Sleeve North America", "Splice Sleeve North America", 
"Splice Sleeve North America", "Splice Sleeve North America", 
"Splice Sleeve North America"), `Coupler Model` = c("Xtender® 500/510 Standard Coupler", 
"Xtender® 500/510 Standard Coupler", "Xtender® 500/510 Standard Coupler", 
"Xtender® 500/510 Standard Coupler", "Xtender® 500/510 Standard Coupler", 
"Xtender® 500/510 Standard Coupler", "Xtender® 500/510 Standard Coupler", 
"Xtender® 500/510 Standard Coupler", "Xtender® 500/510 Standard Coupler", 
"D410 Sleeve-Lock® Grout Sleeve", "D410 Sleeve-Lock® Grout Sleeve", 
"D410 Sleeve-Lock® Grout Sleeve", "D410 Sleeve-Lock® Grout Sleeve", 
"D410 Sleeve-Lock® Grout Sleeve", "D410 Sleeve-Lock® Grout Sleeve", 
"D410 Sleeve-Lock® Grout Sleeve", "D410 Sleeve-Lock® Grout Sleeve", 
"D410 Sleeve-Lock® Grout Sleeve", "NMB", "NMB", "NMB", "NMB", 
"NMB", "NMB", "NMB", "NMB", "NMB"), `Bar Size` = c("No. 5", "No. 5", 
"No. 5", "No. 8", "No. 8", "No. 8", "No. 11", "No. 11", "No. 11", 
"No. 5", "No. 5", "No. 5", "No. 8", "No. 8", "No. 8", "No. 11", 
"No. 11", "No. 11", "No. 5", "No. 5", "No. 5", "No. 8", "No. 8", 
"No. 8", "No. 11", "No. 11", "No. 11"), Failure = c("Bar Fracture", 
"Bar Fracture", "Bar Fracture", "Bar Fracture", "Bar Fracture", 
"Bar Fracture", "Bar Fracture", "Bar Fracture", "Bar Fracture", 
"Bar Fracture", "Bar Pullout", "Bar Pullout", "Bar Fracture", 
"Bar Fracture", "Bar Fracture", "Bar Fracture", "Bar Fracture", 
"Bar Fracture", "Bar Pullout", "Bar Pullout", "Bar Pullout", 
"Bar Fracture", "Bar Fracture", "Bar Fracture", "Bar Fracture", 
"Bar Fracture", "Bar Fracture"), Color = c(1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1
)), row.names = c(NA, -27L), class = c("tbl_df", "tbl", "data.frame"
))

I would like to have the nodes colored depending on the summarized number in the Color column. The current code is:

  collapsibleTreeSummary(
      Mostafa,
      hierarchy = c("Coupler Type", "Coupler Manufacturer", "Bar Size", "Failure"),
      root = "Mechanical Couplers",
      width = 800,
      attribute = "Color",
      zoomable = FALSE,
      collapsed = FALSE
      )

The results I get is :

enter image description here

As you can see, the colors are only assigned to the Failure level and are not carried forward.

For example, for the first level Headed Bar Coupler that has all the Failure types as Bar fracture all the nodes falling under level Headed Bar Coupler should be green (same color since all the Failures were of the wanted type. But for example for first level Grouted Sleeve Coupler, there are some rows with zero. Thus, I want to assign red to the Failure nodes that indicate value 0. All the levels in between should be assigned colors by the gradient.

Desired output is shown below:

enter image description here

Maral Dorri
  • 468
  • 5
  • 17
  • @tospig that was supposed to be `attribute = ` fixed it now! Thank you – Maral Dorri Mar 02 '21 at 23:32
  • @tospig sorry, I have been playing around with it for hours and had an order version in the question. The correct line is `attribute = "Color",` I made a final edit and checked everything else and it should run now – Maral Dorri Mar 02 '21 at 23:53
  • 1
    It's unclear how you want the gradient defined. At the moment you're colouring 1s and 0s. How do you want the gradient calculated? – tospig Mar 02 '21 at 23:59
  • @tospig The gradient should be based on the children's `Color` ratio. So for Mechanical Couplers > Headed Bar ... > Headed... > No.5 all the children have a score of 1 so all of the nodes should be green. For Mechanical Couplers > Grouted ... > Splice ... > No.5, Level 4 (No. 5) should be red, while level 3 (Splice ...) should be lighter orange because the other children (N0. 8 and No. 11) are all green. similarly, level 2 (Grouted ...) should be a lighter shade (like yellow or something in between). The gradient should change based on how many 1s and 0s the final children will have. – Maral Dorri Mar 03 '21 at 00:13

0 Answers0