Rpart2newick: Converts 'rpart' object into Newick tree

View source: R/rpart2newick.r

Rpart2newickR Documentation

Converts 'rpart' object into Newick tree

Description

Converts 'rpart' object into Newick tree

Usage

Rpart2newick(rpart.object)

Arguments

rpart.object

'rpart' object, output of rpart::rpart()

Details

Inspired by 'shaunpwilkinson/rpart2dendro.R' gist.

Value

Newick tree (text string).

Examples

library(rpart)
(fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis))
plot(fit); text(fit, all=TRUE, xpd=TRUE)
library(ape)
tree1 <- read.tree(text=Rpart2newick(fit))
plot(tree1)
nodelabels(tree1$node.label, frame="none", bg="transparent", adj=-0.1)

(fit2 <- rpart(Species ~ ., data=iris))
plot(fit2); text(fit2, all=TRUE, xpd=TRUE)
tree2 <- read.tree(text=Rpart2newick(fit2))
plot(tree2)
nodelabels(tree2$node.label, frame="none", bg="transparent", adj=-0.1)

shipunov documentation built on Feb. 16, 2023, 9:05 p.m.