fancyRpartPlot: A wrapper for plotting rpart trees using prp

Description Usage Arguments Author(s) References Examples

View source: R/fancyRpartPlot.R

Description

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

Usage

1
fancyRpartPlot(model, main="", sub, palettes, ...)

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.

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.

...

additional arguments passed on to prp.

Author(s)

Graham.Williams@togaware.com

References

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## 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)

## Choose different colours

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

Example output

R session is headless; GTK+ not initialized.
Rattle: A free graphical interface for data mining with R.
Version 4.1.0 Copyright (c) 2006-2015 Togaware Pty Ltd.
Type 'rattle()' to shake, rattle, and roll your data.

rattle documentation built on May 29, 2017, 8:29 p.m.

Search within the rattle package
Search all R packages, documentation and source code