Reputation: 333
I've built a decision tree using ctree in R and visualize the tree using the ctree model in the party package.
I am very happy with the results and the overall visualization. However, I cannot interpret the 'confusion' in every leaf node, since the x-axis labels either overlap or are missing!
Currently I use the following command:
plot(fitCtree, main="Title", gp = gpar(fontsize = 2))
I've searched quite a lot to find the (simple?) answer... to no avail. Can you help me out?
Cheers, Arend
Upvotes: 2
Views: 1095
Reputation: 17203
One option that is easily available in node_barplot()
, the panel function employed here, is to rotate the axis labels rather than rotating the entire plot (as suggested in https://stackoverflow.com/a/12000533/4752675 mentioned by @G5W). For example you can set rot = 45, just = c("right", "top")
to obtain a rotation by 45 degrees with top-right justification of the labels.
Depending on the length of the labels, it might be necessary to increase the lower margin of the plot to allow for enough space. One can do this either with pushing a separate viewport - or via the convenience argument margins
that I just added to the development version of partykit
on R-Forge.
As an illustration:
install.packages("partykit", repos = "http://R-Forge.R-project.org")
library("partykit")
ct <- ctree(Species ~ ., data = iris)
plot(ct, margins = c(3, 0, 0, 0),
tp_args = list(rot = 45, just = c("right", "top")))
Upvotes: 2