2

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

asked Dec 7, 2012 at 23:36
2
  • Can you supply a reproducible example please? And explain what 's N? Commented 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. Commented Dec 8, 2012 at 4:07

2 Answers 2

3

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.

answered Dec 9, 2012 at 3:24
Sign up to request clarification or add additional context in comments.

6 Comments

@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.
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 One hint , put a browser() in the begining of innerWeights , and see your node argument...
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 Welcome to R but I am a newbie too ! Do you use R for work or study?
|
0

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.

answered Jan 5, 2017 at 13:37

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.