Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.parttree method #16

Open
grantmcdermott opened this issue Jan 13, 2023 · 1 comment · May be fixed by #18
Open

plot.parttree method #16

grantmcdermott opened this issue Jan 13, 2023 · 1 comment · May be fixed by #18

Comments

@grantmcdermott
Copy link
Owner

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 to Imports, but that's fine.

@grantmcdermott
Copy link
Owner Author

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

@grantmcdermott grantmcdermott linked a pull request Jul 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant