1

我正在尝试使用 and包创建一个collapsibletree对象。按照这个示例,我尝试为我的树分配颜色,但我没有得到任何东西。library(collapsibleTree)library(dplyr)

下面提供了几行数据框。该Failure列是分类的,具有三个选项c("Bar fracture", "Bar pullout", "Coupler failure")。我创建了一个名为的新列Color,并将值 1 分配给表示Failure类型为Bar fracture的每一行,并将 0 分配给表示其他类型的每一行(其他两个类别)。

> 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"
))

我希望根据Color列中的汇总数字对节点进行着色。当前代码是:

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

我得到的结果是:

在此处输入图像描述

如您所见,颜色仅分配给故障级别,不会结转。

例如,对于Headed Bar Coupler具有所有Failure类型的第一级,Bar fracture所有节点都属于该级别Headed Bar Coupler应该是绿色(相同的颜色,因为所有Failures 都是想要的类型。但是例如对于第一级Grouted Sleeve Coupler,有一些行为零。因此,我想将红色分配给Failure指示值 0 的节点。中间的所有级别都应通过渐变分配颜色。

所需的输出如下所示:

在此处输入图像描述

4

0 回答 0