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")
and my tree would look like
enter image description here
how can I modified that plot where it would show N= on every circle nodes , not only the black or the final node.
Thanks
-
Can you supply a reproducible example please? And explain what 's N?agstudy– agstudy2012年12月08日 01:14:08 +00:00Commented Dec 8, 2012 at 1:14
-
Oh,N in here is volume , say of the sample, N = 100 , meanings 100 fall into the black square box. but I want to add N in box b and c .. Say if 150 fall into b oval, I want to add N = 150 in there.JPC– JPC2012年12月08日 04:07:17 +00:00Commented Dec 8, 2012 at 4:07
2 Answers 2
enter image description here
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'))
}
I plot the tree
plot(tt, type='simple', inner_panel = innerWeights)
PS: the results depends on a random generated data, so you will not probably get the same plot.
-
1@JPC you are welcome. Next time please try to produce a good reproducible example. when I have time I'll do version with ggplot2 inner_function.agstudy– agstudy2012年12月10日 15:21:44 +00:00Commented Dec 10, 2012 at 15:21
-
I 'm trying to add back node labels ("A", "B", "C" ) into the inner_panel, but didn't have any success. Could you please show me how to ? Thank you.JPC– JPC2012年12月12日 14:42:46 +00:00Commented Dec 12, 2012 at 14:42
-
@JPC One hint , put a browser() in the begining of innerWeights , and see your node argument...agstudy– agstudy2012年12月12日 14:45:35 +00:00Commented Dec 12, 2012 at 14:45
-
thank you ! I need to send you a thank you card! really ! I am very new to R , but the R community has been great to newbies like me.JPC– JPC2012年12月12日 16:28:10 +00:00Commented Dec 12, 2012 at 16:28
-
@JPC Welcome to R but I am a newbie too ! Do you use R for work or study?agstudy– agstudy2012年12月12日 16:40:00 +00:00Commented Dec 12, 2012 at 16:40
When exporting the decision tree, change the dimensions of the image. for a decision tree with 200 terminal nodes the width should be about 30.000.