library(tree) data(cars) cars.tr<-tree(dist~speed,data=cars) print(cars.tr) plot(cars.tr,type="u") text(cars.tr) # 理由不明だが、繰り返す必要あり plot(cars.tr,type="u") text(cars.tr) (cars.tr1<-prune.tree(cars.tr,best=4)) plot(cars.tr1); text(cars.tr1,all=T) plot(cars$speed,cars$dist) partition.tree(cars.tr1,add=T,col=2) data(iris) (iris.tr<-tree(Species~.,data=iris)) plot(iris.tr,type="u"); text(iris.tr) (iris.tr1<-snip.tree(iris.tr,nodes=c(12,7))) plot(iris.tr1,type="u");text(iris.tr1) iris.label<-c("S", "C", "V")[iris[, 5]] plot(iris[,3],iris[,4],type="n") text(iris[,3],iris[,4],labels=iris.label) partition.tree(iris.tr1,add=T,col=2,cex=1.5) iris.color<-c("red","blue","green")[iris[,5]] plot(iris[,3],iris[,4],col=iris.color) partition.tree(iris.tr1,add=T,col=2,cex=1.5)