While I'm very pleased with the results I get with rpart and rpart.plot, I would like to change the scientific notation of the dependent variable in the plots into integers. Right now all my 5 or more digit numbers are displayed using scientific notation. I managed to find this: http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8423.html but I do not fully understand what to change, and to what.
I don't see a quick solution to this. You could contact the maintainer of the rpart.plot package, Stephen Milborrow maintainer("rpart.plot") or you could try to modify the rpart.plot() function yourself to meet your needs rpart.plot Jean Jay wrote on 08/25/2011 05:30:25 AM:> > While I'm very pleased with the results I get with rpart and > rpart.plot, I would like to change the scientific notation of the > dependent variable in the plots into integers. Right now all my 5 or > more digit numbers are displayed using scientific notation. > > I managed to find this: > http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8423.html > but I do not fully understand what to change, and to what. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
Jay <josip.2000 at gmail.com> wrote:> While I'm very pleased with the results I get with rpart and > rpart.plot, I would like to change the scientific notation of the > dependent variable in the plots into integers. Right now all my 5 or > more digit numbers are displayed using scientific notation.One way of getting rpart.plot to always display the response in integer format (i.e. no scientific notation) is to use sprintf like this: library(rpart.plot) library(earth) # for the ozone1 data data(ozone1) ozone1$O3 <- 1000 * ozone1$O3 # for demo want big numbers tree <- rpart(O3~., data=ozone1) node.fun <- function(x, labs, digits, varlen) { sprintf("%0.f", x$frame$yval) } rpart.plot(tree, node.fun=node.fun) The code above uses its own node-label-formatting function, node.fun For details see the prp help page and the rpart.plot vignette Chapter 5. The "%0.f" tells sprintf to format as fixed point with zero digits after the decimal point. The "x$frame$yval" is the predicted response at each node (look at tree$frame to get the idea). I find sprintf easier to use than R's format function. It's (arguably) less idiosyncratic, and works the same way across many languages, including C, C++, Python, Java, and R. But as an alternative, with a bit of experimentation you may get format to do what you want, c.f. the description of the "digits" argument on the prp help page.
Possibly Parallel Threads
- rpart Error in yval[, 1] : incorrect number of dimensions
- Error when I try to build / plot a tree using rpart()
- Some questions on Rpart algorithm
- method of rpart when response variable is binary?
- text.rpart for the "class" method doesn't act on label="yprob"