I have an issue where I am using mainly categorical data, set to a class of factor, in a classification tree. I am using the partykit
package in R and not party
as previous answers here suggested that the former package is better for manipulation of graphics output.
I do not have many nodes (about 7) in my real dataset, but I have quite a few factor levels for some variables and I am encountering the issue that the factor levels on the left side of the split and those from the right side are interfering with each other. Specifically, this occurs because of the horizontal orientation of the factor level lists in combination with the length of the factor levels.
I can reproduce the issue using the Aids2 dataset in the MASS
package. This is a nonsense example, but it generates the behaviour I wish to solve
library("partykit")
SexTest <- ctree(sex ~ ., data=Aids2)
plot(SexTest)
If you look at the node split information for Node 1, you will see the behaviour I am describing:
In my real data frame, shrinking the font only works if I get it down to 4-point, which is unreadable.
Is there some way to define a text box for that string, and enable the text to wrap? I've looked through par
and gpar
trying to find a solution, but have been unsuccessful. Another option which would be suitable would be to stagger the vertical position of the factor information for each node, so that they are situated one under the other.