Reorder alphanumeric characters in rpart.plot

43 Views Asked by At

I am making a multi-classification decision tree using rpart and rpart.plot. My classes are 0, 1, 2, 2.5, 3, 3.5, 4 and 4.5. I am using extra=4 for rpart.plot to display the probability per class of observations in the node. Here you can see an example node as rpart.plot outputs. rpart.plot output

The predicted class is 2 (ignore "OOM" please it's not relevant here), represented by the .72 in the top right spot. This is not how I want the nodes displayed though. I want the classifications to be in ascending numeric order from top left to bottom right. The top block in the below image shows a generic rpart.plot output node with the name of the classification in the position where the probability would be. The bottom block shows the classes in the order I want them in.

Output vs Want

I believe this is due to " . " coming before " 5 " in order of characters, is there any way to change the order of characters or to force the classes into an order through rpart?

I have changed the naming of the classes to have them sorted in the order I would like but this is less than ideal as it makes the classes more confusing.

0

There are 0 best solutions below