In the partykit
package, I want to round and format the numeric labels on the edges. How do I do this?
For example, below, I'd like to be able to convert <11897.65
to <11,898
. Rounding to 0 digits after the decimal place and inserting a comma after the thousands.
Asked
Active
Viewed 469 times
0

dal233
- 80
- 1
- 6
-
The best way that I've found so far to deal with this is simply to use `rpart.plot`. (Assuming you've created the tree in `rpart`.) – dal233 Jan 04 '16 at 04:02
1 Answers
0
The labeling of the edges is done by the panel function generated by edge_simple()
, see ?edge_simple
. You can pass arguments to the edge panel generator using ep_args
, e.g.,
library("partykit")
ct <- ctree(Species ~ ., data = iris)
plot(ct, ep_args = list(digits = 0))
Inserting a comma to separate thousands is not supported in edge_simple()
. If you want to have it, you can copy the code of edge_simple()
and add this type of formatting yourself. However, I would recommend to simply divide the corresponding variable by 1000
which would yield something easily readable.

Achim Zeileis
- 15,710
- 1
- 39
- 49