加上一句「;填写「;属性设置为data.tree对象,用于R中的可折叠树
我们一直在使用带有加上一句「;填写「;属性设置为data.tree对象,用于R中的可折叠树,r,hierarchical-data,data.tree,collapsibletree-r,R,Hierarchical Data,Data.tree,Collapsibletree R,我们一直在使用带有collapsabletree()的数据帧来制作层次系统的交互式、美观的dendogram。但是我们遇到的问题是,在使用数据帧时很难获得我们想要的定制,而且从collapsabletree文档中可以看出,使用data.tree结构提供了更大的灵活性。例如,如果我们希望使用数据帧为特定节点着色,我们需要执行以下操作: library(dplyr) library(data.tree) library(collapsibleTree) colors <- rep('gray
collapsabletree()
的数据帧来制作层次系统的交互式、美观的dendogram。但是我们遇到的问题是,在使用数据帧时很难获得我们想要的定制,而且从collapsabletree
文档中可以看出,使用data.tree结构提供了更大的灵活性。例如,如果我们希望使用数据帧为特定节点着色,我们需要执行以下操作:
library(dplyr)
library(data.tree)
library(collapsibleTree)
colors <- rep('gray', 15)
colors[1] <- 'red' # root
colors[3] <- 'red' # child we want to emphasize
colors[15] <- 'red' # grand child we want to emphasize
original_data_frame %>%
collapsibleTree(
hierarchy = c("level_2",
"level_3",
"level_4",
"level_5",
"level_6",
"level_7"
),
root = "level_1",
fill = colors
)
original_as_tree <- original_data_frame %>%
mutate(pathString =
paste(
level_1,
level_2,
level_3,
level_4,
level_5,
level_6,
level_7,
sep = "/"),
pathString = str_remove_all(pathString, "/NA")) %>%
as.Node()
original_as_tree$color <- "gray"
original_as_tree$Boat$color <- "red"
collapsibleTree(original_as_tree,
fill = original_as_tree$color)
structure(list(level_1 = c("Sea System", "Sea System", "Sea System",
"Sea System", "Sea System", "Sea System"), level_2 = c("System Engineering",
"Boat", "Boat", "Boat", "Boat", "Boat"), level_3 = c("Core Systems Engineering",
"Auxiliary Systems", "Total Ship Integration/Engineering", "Electric Plant",
"Hull Structure", "Hull Structure"), level_4 = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
), level_5 = c(NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_), level_6 = c(NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_),
level_7 = c("GREENLAND ENTERPRISES, INC.", "3M PURIFICATION INC.",
"5TH AXIS, LLC", "901 D, LLC", "A. M. CASTLE & CO.", "A.M. CASTLE & CO."
)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"