我使用R包data.tree创建了一个树。我想只编辑顶部节点,但我不知道如何使用SetNodeStyle引用它。这是代码:
library(data.tree)
truven <- Node$new("truven")
opioid <- truven$AddChild("opioid")
iro.only <- opioid$AddChild("iro.only")
ero.n.iro <- opioid$AddChild("ero.n.iro")
ge.27mth <- ero.n.iro$AddChild("ge.27mth")
l.27mth <- ero.n.iro$AddChild("l.27mth")
ero.only <- opioid$AddChild("ero.only")
SetGraphStyle(truven, rankdir = "TB")
SetEdgeStyle(truven, arrowhead = "vee", color = "grey35", penwidth = 1)
SetNodeStyle(truven, style = "filled,rounded", shape = "box", fillcolor = "Yellow",
fontname = "helvetica", tooltip = GetDefaultTooltip)
SetNodeStyle(truven$truven, style = "filled,rounded", shape = "box", fillcolor = "Green",
fontname = "helvetica", tooltip = GetDefaultTooltip)
plot(truven)
注意我试图用truven $ truven引用顶级节点。它不起作用。
答案 0 :(得分:0)
试试这个:
SetNodeStyle(truven$truven, style = "filled,rounded", shape = "box", fillcolor = "Green", inherit = FALSE, fontname = "helvetica", tooltip = GetDefaultTooltip)
它应该可以正常工作,我认为你在inherit = FALSE
函数中错过了SetNodeStyle
。