View source: R/plot.PPTreeExtclass.R
| plot.PPtreeExtclass | R Documentation |
Visualizes a Projection Pursuit (PP) classification tree using grid graphics. The function creates a hierarchical tree diagram showing the structure of splits and terminal nodes with class assignments. Supports automatic scaling for large trees.
## S3 method for class 'PPtreeExtclass'
plot(
x,
font.size = 17,
width.size = 1,
main = "Projection Pursuit Classification Tree",
sub = NULL,
auto.scale = TRUE,
min.width = NULL,
min.height = NULL,
...
)
x |
An object of class |
font.size |
Numeric. Font size for text labels in the plot.
Default is 17. Will be automatically reduced for large trees when
|
width.size |
Numeric. Width scaling factor for graphical elements
(nodes, edges). Default is 1. Will be automatically adjusted for large
trees when |
main |
Character string. Main title for the plot. Default is "Projection Pursuit Classification Tree". |
sub |
Character string or NULL. Subtitle for the plot. Default is NULL (no subtitle). |
auto.scale |
Logical. If TRUE (default), automatically adjusts plot dimensions and font size based on tree size. Recommended for trees with more than 20 terminal nodes or depth greater than 15. |
min.width |
Numeric or NULL. Minimum width (number of terminal nodes)
for the plot when |
min.height |
Numeric or NULL. Minimum height (tree depth) for the plot
when |
... |
Additional arguments (currently not used). |
The plot displays:
Internal nodes: Shown as ellipses with the projection used for splitting (e.g., "proj1 * X")
Terminal nodes: Shown as gray rectangles with the assigned class label
Edges: Labeled with split rules ("< cutN" for left child, ">= cutN" for right child)
Node IDs: Small boxes at the top of each node
Auto-scaling behavior:
When auto.scale = TRUE and the tree has more than 20 terminal nodes
or depth greater than 15:
Font size is reduced: max(10, 17 - floor((n_terminal - 20) / 5))
Width size is reduced: max(0.7, 1 - (n_terminal - 20) * 0.01)
Width is set to: max(n_terminal, n_classes)
Height is set to: tree depth
Manual scaling:
When auto.scale = FALSE, you can control dimensions with
min.width and min.height.
Invisibly returns a list with:
width |
Numeric. The width used for plotting (number of terminal nodes) |
height |
Numeric. The height used for plotting (tree depth) |
font.size |
Numeric. The final font size used (after auto-scaling) |
This function requires the grid package. It will create a new graphics
page using grid.newpage().
For very large trees (>50 terminal nodes), consider:
Exporting to a large PNG or PDF file
Manually reducing font.size further
Pruning the tree before plotting
library(grid)
# Example with penguins dataset
data(penguins)
penguins <- na.omit(penguins[, -c(2,7)])
penguins_ppt <- PPtreeExtclass(species~bill_len + bill_dep +flipper_len +
body_mass, data = penguins, PPmethod = "PDA", srule = FALSE )
plot(penguins_ppt,
main = "Penguins Classification with PPtreeExt",
font.size = 8,
width.size = 0.7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.