fancyRpartPlot: A wrapper for plotting rpart trees using prp

View source: R/fancyRpartPlot.R

fancyRpartPlotR Documentation

A wrapper for plotting rpart trees using prp

Description

Plots a fancy RPart decision tree using the pretty rpart plotter.

Usage

fancyRpartPlot(model, main="", sub, caption, palettes, type=2, ...)

Arguments

model

an rpart object.

main

title for the plot.

sub

sub title for the plot. The default is a Rattle string with date, time and username.

caption

caption for bottom right of plot.

palettes

a list of sequential palettes names. As supported by RColorBrewer::brewer.pal the available names are Blues BuGn BuPu GnBu Greens Greys Oranges OrRd PuBu PuBuGn PuRd Purples RdPu Reds YlGn YlGnBu YlOrBr YlOrRd.

type

the type of plot to generate (2).

...

additional arguments passed on to prp.

Author(s)

Graham.Williams@togaware.com

References

Package home page: https://rattle.togaware.com

Examples

## Use rpart to build a decision tree.

## Not run: library(rpart)

## Set up the data for modelling.

set.seed(42)
ds     <- weather
target <- "RainTomorrow"
risk   <- "RISK_MM"
ignore <- c("Date", "Location", risk)
vars   <- setdiff(names(ds), ignore)
nobs   <- nrow(ds)
form   <- formula(paste(target, "~ ."))
train  <- sample(nobs, 0.7*nobs)
test   <- setdiff(seq_len(nobs), train)
actual <- ds[test, target]
risks  <- ds[test, risk]

# Fit the model.

fit <- rpart(form, data=ds[train, vars])

## Plot the model.

fancyRpartPlot(fit)

## Choose different colours.

fancyRpartPlot(fit, palettes=c("Greys", "Oranges"))

## Add a main title to the plot.

fancyRpartPlot(fit, main=target) 


## End(Not run)

rattle documentation built on March 21, 2022, 5:06 p.m.