grantmcdermott / parttree

R package for plotting simple decision tree partitions
http://grantmcdermott.com/parttree
Other
93 stars 23 forks source link

Add dedicated plot.parttree method #18

Open grantmcdermott opened 3 months ago

grantmcdermott commented 3 months ago

Closes #14. Closes #16. Addresses #9 (even if it doesn't provide a formal fix).

This PR introduces a formal "parttree" class and provides a native plot.parttree method using base R graphics (powered by tinyplot). The ggplot2 scaffolding is still supported via geom_parttree().

Example from the new README:

library(rpart)
library(parttree)

fit = rpart(Kyphosis ~ Start + Age, data = kyphosis)
fit_pt = parttree(fit)
# Default plot
plot(fit_pt)

# Cusomized plot 
plot(
  fit_pt,
  border  = NA, # no partition borders
  pch     = 19, # filled points
  alpha   = 0.6, # point transparency
  grid    = TRUE, # background grid
  palette = "classic", # new colour palette
  xlab    = "Topmost vertebra operated on", # custom x title
  ylab    = "Patient age (months)", # custom y title
  main    = "Tree predictions: Kyphosis recurrence" # custom title
)

Created on 2024-07-25 with reprex v2.1.0

It includes several smaller changes at the same time, e.g. flipaxes is renamed to flip.

grantmcdermott commented 3 months ago

Hmmm. Workflows are failing due missing ggplot2 installation. But the log file shows that it has been installed. https://github.com/grantmcdermott/parttree/actions/runs/10102909981/job/27939351692?pr=18#step:5:4882

?