Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grantmcdermott/parttree
R package for plotting simple decision tree partitions
https://github.com/grantmcdermott/parttree
Last synced: about 2 months ago
JSON representation
R package for plotting simple decision tree partitions
- Host: GitHub
- URL: https://github.com/grantmcdermott/parttree
- Owner: grantmcdermott
- License: other
- Created: 2020-03-25T05:52:20.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-27T01:34:53.000Z (about 2 months ago)
- Last Synced: 2024-07-27T20:55:25.302Z (about 2 months ago)
- Language: R
- Homepage: http://grantmcdermott.com/parttree
- Size: 5.84 MB
- Stars: 90
- Watchers: 5
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```[![R-CMD-check](https://github.com/grantmcdermott/parttree/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/grantmcdermott/parttree/actions/workflows/R-CMD-check.yaml)
[![Docs](https://img.shields.io/badge/docs-homepage-blue.svg)](https://grantmcdermott.com/parttree/index.html)Visualize simple 2-D decision tree partitions in R. The **parttree**
package is optimised to work with [**ggplot2**](https://ggplot2.tidyverse.org/),
although it can be used to visualize tree partitions with base R graphics too.## Installation
This package is not yet on CRAN, but can be installed from [GitHub](https://github.com/)
with:``` r
# install.packages("remotes")
remotes::install_github("grantmcdermott/parttree")
```
## QuickstartThe **parttree** [homepage](https://grantmcdermott.com/parttree/index.html)
includes an introductory vignette and detailed documentation. But here's a
quickstart example using the
["kyphosis"](https://search.r-project.org/CRAN/refmans/rpart/html/kyphosis.html)
dataset that comes bundled with the **rpart** package. In this case, we are
interested in predicting kyphosis recovery after spinal surgery, as a function
of 1) the number of topmost vertebra that were operated, and 2) patient age.
The key visualization layer below---provided by this package---is
`geom_partree()`.```{r quickstart}
library(rpart) # For the dataset and fitting decisions trees
library(parttree) # This package (will automatically load ggplot2 too)fit = rpart(Kyphosis ~ Start + Age, data = kyphosis)
ggplot(kyphosis, aes(x = Start, y = Age)) +
geom_parttree(data = fit, alpha = 0.1, aes(fill = Kyphosis)) + # <-- key layer
geom_point(aes(col = Kyphosis)) +
labs(
x = "No. of topmost vertebra operated on", y = "Patient age (months)",
caption = "Note: Points denote observations. Shading denotes model predictions."
) +
theme_minimal()
```