Scaling plots in the terminal nodes of ctree graph

1.3k views Asked by At

I am trying to scale the plots that appear in the terminal nodes of a ctree. I have tried using the yscale parameter but this just results plots that extend beyond the plotting window

For example: Here is a ctree for two exponential distributions

set.seed(1)    
classA <-data.frame(class = "a", val = round(rexp(500, rate = 0.2),0))
classB <-data.frame(class = "b", val = round(rexp(500, rate = 0.05),0))

df <- as.data.frame(rbind(classA,classB))

ct = ctree(val~., data = df)
plot(ct)

Now if I try to scale the y axis of the plots from 0 to 70 to zoom in on the box plots and cut-off the outliers, I can use:

plot(ct,terminal_panel = node_boxplot(ct,yscale =c(0,70)))

This works to scale the y axis, but now the plot extends beyond the plotting box.

Sorry I would show images, but don't have enough privileges on stackoverflow yet.

Thanks for any suggestions

1

There are 1 answers

4
Achim Zeileis On BEST ANSWER

First of all: In an example like this it would be better to log-transform the response because then the association tests employed in ctree() will have more power to detect differences for splitting in the tree. Possibly some small continuity correction might help if there are exact zeros.

But, of course, the problem of the proper scaling in the terminal nodes is separate from this. The reason was that the viewports for the terminal nodes were not set to clip = TRUE and hence didn't clip graphical elements outside the viewport region.

I've just fixed this problem in the partykit package on R-Forge. A new CRAN release is not scheduled yet but you can either check out the partykit-SVN from R-Forge or just download the current partykit/R/plot.R source code.