Learn R Programming

PPtreeExt (version 0.1.0)

plot.PPtreeExtclass: Plot Projection Pursuit Classification Tree

Description

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.

Usage

# S3 method for 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,
  ...
)

Value

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)

Arguments

x

An object of class PPtreeclass or PPtreeExtclass containing the tree structure, projection vectors, and split points.

font.size

Numeric. Font size for text labels in the plot. Default is 17. Will be automatically reduced for large trees when auto.scale = TRUE.

width.size

Numeric. Width scaling factor for graphical elements (nodes, edges). Default is 1. Will be automatically adjusted for large trees when auto.scale = TRUE.

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 auto.scale = FALSE. If NULL, uses the number of classes in the data. Default is NULL.

min.height

Numeric or NULL. Minimum height (tree depth) for the plot when auto.scale = FALSE. If NULL, uses calculated tree depth. Default is NULL.

...

Additional arguments (currently not used).

Details

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.

Examples

Run this code
# \donttest{
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)
# }

Run the code above in your browser using DataLab