1
votes

I am using the R programming language. I ran a decision tree function using the "rpart" library:

library(rpart)
z.auto <- rpart(Mileage ~ Weight, car.test.frame)

From here, I tried to plot the results:

 plot(z.auto)

This returns the following plot:enter image description here

As well as several warning messages:

Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
2: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
3: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
4: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
5: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
6: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
7: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
8: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
9: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter

I am trying to add more information this plot (such as the variable names and the decision rules). I did some research and found out that you can add labels to this plot:

text(z.auto, use.n=TRUE)

This returns the following plot:

enter image description here

This plot is better - but the text is being cut off towards the bottom. Is there a straightforward way to change the internal size of the plot so that all the text appears without being cut off?

Note: I am using a computer that does not have an internet connection or a USB port - it just has R with some common libraries (e.g. ggplot2, rpart, party, partykit, etc.), I am NOT able to install the "rpart.plot" library on my computer (https://www.rdocumentation.org/packages/rpart.plot/versions/3.0.9), otherwise I would have tried to use this library instead.

Thank you

2
is there way to ensure that the plot is scaled to automatically fit the page? is this problem easier to solve using the libraries "party" or "partykit"?stats555

2 Answers

1
votes

Use xpd=TRUE. Also cex= might be helpful to scale font size.

plot(z.auto)
text(z.auto, use.n=TRUE, xpd=TRUE, cex=.8)

enter image description here

1
votes

You can use rattle package for plotting of CART like

library(rpart)
library(rpart.plot)
library(rattle)

z.auto <- rpart(Mileage ~ Weight, car.test.frame)
#Plotting using `rpart.plot` package
prp(z.auto, type = 1)

enter image description here

#Plotting using `rattle` package
fancyRpartPlot(z.auto) 

enter image description here