I want to create a decision tree plot which display an overlay histogram in each node as shown in the picture:
The following code creates the left side picture:
library(earth)
library(rpart)
library(rpart.plot)
a <- rpart(O3~., data=ozone1, cp=.2)
prp(a, type=4, fallen=T, branch=.3, round=0, leaf.round=9,
clip.right.labs=F, under.cex=1,
box.palette="GnYlRd",
prefix="ozone\n", branch.col="gray", branch.lwd=2,
extra=101, under=T, lt=" < ", ge=" >= ", cex.main=1.5)
I think the node.fun from the rpart.plot can do the job, but I don't know how to implement it.
Unfortunately with the current version 2.1.2 of rpart.plot you can't do that.
As you mention, you could perhaps use a customised node.fun to draw histograms. But rpart.plot doesn't know how to figure out the plotted size of the histograms, so it doesn't know how to position the elements of the plot correctly on the page.
I'll add it to the package TODO list and look into implementing it, but unfortunately that won't happen soon.