问题描述
我正在尝试用igraph绘制决策树。但是,我不知道如何创建允许使用igraph绘制决策树的数据结构。
有什么提示吗?
解决方法
这个例子:
library(data.tree)
library(igraph)
acme <- Node$new("Acme Inc.")
accounting <- acme$AddChild("Accounting")
software <- accounting$AddChild("New Software")
standards <- accounting$AddChild("New Accounting Standards")
research <- acme$AddChild("Research")
newProductLine <- research$AddChild("New Product Line")
newLabs <- research$AddChild("New Labs")
it <- acme$AddChild("IT")
outsource <- it$AddChild("Outsource")
agile <- it$AddChild("Go agile")
goToR <- it$AddChild("Switch to R")
print(acme)
plot(as.igraph(acme,directed = TRUE,direction = "climb"))
来源:https://cran.r-project.org/web/packages/data.tree/vignettes/data.tree.html