使用ctree显示每个节点的体积,以R表示 [英] show volume in each node using ctree , plot in R
本文介绍了使用ctree显示每个节点的体积,以R表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以告诉我如何在每个节点中增加音量,而不是最后一个节点音量
can any one please show me how to add volume in each of the nodes , instead of the final node volume
t <- ctree(is_return ~ a + b + c)
plot(t, type="simple")
我的树看起来像
如何修改该图,使其在每个圆节点上显示N =,而不仅仅是黑色或最后一个节点.
how can I modified that plot where it would show N= on every circle nodes , not only the black or the final node.
谢谢
推荐答案
该想法是指定用于绘制内部节点的面板功能.
The idea is to specify a panel functions for plotting inner nodes.
我生成一些数据,然后生成树
I generate some data, and the tree
lls <- data.frame(N = gl(3, 50, labels = c("A", "B", "C")),
a = rnorm(150) + rep(c(1, 0,150)),
b = runif(150))
pond= sample(1:5,150,replace=TRUE)
tt <- ctree(formula=N~a+b, data=lls,weights = pond)
自定义内部绘图功能.我画一个圆圈,写一些权重.
The custom inner plot function. I draw a circle where i write the some of weights.
innerWeights <- function(node){
grid.circle(gp = gpar(fill = "White", col = 1))
mainlab <- paste( node$psplit$variableName, "\n(n = ")
mainlab <- paste(mainlab, sum(node$weights),")" , sep = "")
grid.text(mainlab,gp = gpar(col='red'))
}
我画了树
plot(tt, type='simple', inner_panel = innerWeights)
PS:结果取决于随机生成的数据,因此您可能不会获得相同的图.
PS: the results depends on a random generated data, so you will not probably get the same plot.
这篇关于使用ctree显示每个节点的体积,以R表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文