View source: R/NPT_discrete_plot.R
| NPT_discrete_plot | R Documentation |
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.
NPT_discrete_plot(data, point_size = 2.5)
data |
A data frame containing niche classification results, typically the
|
point_size |
Numeric value specifying the size of nodes in the tree plot.
Default is |
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:
Parse niche codes to extract individual dimension values
Create nodes for each unique cluster combination
Establish parent-child relationships between levels
Generate the final graph structure for visualization
A ggplot object representing the niche classification tree. The plot
can be further customized using standard ggplot2 functions.
The function assumes that niche codes are comma-separated strings
Layer names are automatically extracted from column names (excluding "species" and "niche_code")
If the number of layer names doesn't match dimensions, generic names (Layer1, Layer2, etc.) are used
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.
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.
## Not run:
# 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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.