Open grantmcdermott opened 1 year ago
Once tinyplot gets on CRAN (and gets support for type = "rect"
), this should be fairly straightforward.
library(rpart)
library(parttree)
#> Loading required package: ggplot2
library(tinyplot)
palette("classic")
fit = rpart(Kyphosis ~ Start + Age, data = kyphosis)
pt = parttree(fit)
plt(
Age ~ Start | Kyphosis, kyphosis,
pch = 19, grid = TRUE,
xlab = "No. of topmost vertebra operated on",
ylab = "Patient age (months)"
)
corners = par("usr")
xmin = pt$xmin; xmin[xmin==-Inf] = corners[1]
ymin = pt$ymin; ymin[ymin==-Inf] = corners[3]
xmax = pt$xmax; xmax[xmax==Inf] = corners[2]
ymax = pt$ymax; ymax[ymax==Inf] = corners[4]
rect(
xmin, ymin, xmax, ymax,
col = adjustcolor(palette(), alpha.f = 0.1)[pt$Kyphosis]
)
Created on 2024-02-09 with reprex v2.1.0
Would probably require adding extra attributes to the parttree object (name for x and y variables, fml call for evaluating the data object, etc.) A dedicatedbase plot method would also suggest that ggplot2 should move from
Depends
toImports
, but that's fine.