Learn R Programming

MultiTraits (version 0.6.0)

NPT_discrete_plot: Visualize Discrete Niche Classification Tree

Description

This function creates a hierarchical tree visualization of the discrete niche classification results generated by NPT_discrete. The visualization displays the niche classification structure as a directed tree graph, where each level represents a niche dimension and nodes represent different clusters within each dimension.

Usage

NPT_discrete_plot(data, point_size = 2.5)

Value

A ggplot object representing the niche classification tree. The plot can be further customized using standard ggplot2 functions.

Arguments

data

A data frame containing niche classification results, typically the niche_classification output from NPT_discrete. Must contain:

  • species - Character column with species names

  • niche_code - Character column with comma-separated niche codes (e.g., "1,2,1")

  • Additional columns representing cluster assignments for each dimension (used as layer names in the visualization)

point_size

Numeric value specifying the size of nodes in the tree plot. Default is 2.5.

Details

The function constructs a hierarchical tree visualization where:

  • Root node: Represents the starting point of the classification

  • Level 1 nodes: Show clusters in the first niche dimension

  • Level 2 nodes: Show clusters in the second niche dimension, connected to their parent clusters from level 1

  • Subsequent levels: Continue the hierarchical pattern for additional dimensions

Visualization Features:

  • Different colors for each niche dimension level using NPG color palette

  • Directed edges showing the hierarchical relationships

  • Node labels indicating cluster numbers

  • Legend showing niche levels

  • Automatic detection of the number of dimensions from niche codes

Tree Construction Algorithm:

The function automatically determines the number of niche dimensions by parsing the first niche code, then recursively builds the tree structure:

  1. Parse niche codes to extract individual dimension values

  2. Create nodes for each unique cluster combination

  3. Establish parent-child relationships between levels

  4. Generate the final graph structure for visualization

References

  1. Winemiller, K. O., Fitzgerald, D. B., Bower, L. M., & Pianka, E. R. (2015). Functional traits, convergent evolution, and periodic tables of niches. Ecology letters, 18(8), 737-751.

  2. Pianka, E. R., Vitt, L. J., Pelegrin, N., Fitzgerald, D. B., & Winemiller, K. O. (2017). Toward a periodic table of niches, or exploring the lizard niche hypervolume. The American Naturalist, 190(5), 601-616.

Examples

Run this code
if (FALSE) {
# Load and prepare data
data(PFF)
rownames(PFF) <- PFF$species
PFF_traits <- PFF[, c("SLA", "SRL", "Leaf_Nmass", "Root_Nmass","Height",
                      "Leaf_CN", "Root_CN","SeedMass", "FltDate", "FltDur")]
# Perform log transformation of data and remove missing values
PFF_traits <- log(na.omit(PFF_traits))
head(PFF_traits)
# Define trait dimensions
dimension <- list(Grow = c("SLA", "SRL", "Leaf_Nmass", "Root_Nmass"),
                  Survive = c("Height", "Leaf_CN", "Root_CN"),
                  Reproductive = c("SeedMass", "FltDate", "FltDur"))

set.seed(123)
discrete_result <- NPT_discrete(data = PFF_traits, dimension = dimension)
NPT_discrete_plot(discrete_result$niche_classification)

}

Run the code above in your browser using DataLab