Learn R Programming

rattle (version 3.3.0)

fancyRpartPlot: 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, ...)

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.
...
additional arguments passed on to prp.

References

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

Examples

Run this code
## Use rpart to build a decision tree.

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]

# Build the model.

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

## Plot the model.

fancyRpartPlot(model)

Run the code above in your browser using DataLab