# MultiTraits_tutorial

#### Yan He

#### 2025.10.1

## Introduction

MultiTraits is a comprehensive R package designed for advanced analysis and visualization of multidimensional plant traits. It provides a standardized workflow and intuitive visualization tools, streamlining the exploration of complex trait relationships for researchers, educators, and students. The package integrates four key analytical modules: Competitors–Stress Tolerators–Ruderals (CSR) strategy analysis, Leaf–Height–Seed (LHS) strategy analysis, Niche Periodic Table (NPT) analysis, and Plant Trait Network (PTN) analysis. These modules offer complementary perspectives, fostering a more comprehensive understanding of multidimensional trait variation patterns in plants. This tutorial aims to guide users through the core functionalities and practical applications of the MultiTraits package. Through hands-on demonstrations, we show how these analytical modules can be used to explore multidimensional relationships among plant traits, including essential steps in data preparation, analysis workflows, and results visualization.

## Installation

### From CRAN (recommended)

    # install.packages("MultiTraits")

### From GitHub (development version)

    # if (!requireNamespace("devtools", quietly = TRUE)) {install.packages("devtools")}
    # devtools::install_github("biodiversity-monitoring/MultiTraits")

## Main Functions

Module | Function | Description
--- | --- | ---
CSR Module | `CSR()` | Classifies plant species’ CSR ecological strategies based on leaf traits (LA, LDMC, and SLA) using the Pierce et al. (2017) method.
| `CSR_hodgson()` | Implements the Hodgson et al. (1999) method for CSR classification.
| `CSR_plot()` | Provides advanced ternary plot visualizations for CSR analysis to explore plant adaptation to different environments.
LHS Module | `LHS()` | Analyzes LHS strategies using SLA, plant height, and seed mass.
| `LHS_plot()` | Visualizes three-dimensional trait distributions in LHS space.
| `LHS_strategy_scheme()` | Classifies strategies based on the LHS scheme.
NPT Module | `NPT_discrete()` | Supports discrete niche classification schemes. Performs PCA and clustering (CART or K-means) to group species within each dimension.
| `NPT_discrete_plot()` | Visualizes the discrete niche classification scheme.
| `NPT_continuous()` | Supports continuous niche classification schemes. Performs a hierarchical PCA approach.
| `NPT_continuous_plot()` | Visualizes the results of the continuous niche classification.
PTN Module | `PTN_corr()` | Offers correlation computation and visualization for trait networks.
| `PTN()` | Generates trait correlation networks.
| `PTN_metrics()` | Quantifies network metrics for trait networks.
| `PTN_plot()` | Visualizes the trait network graph.

### Example Datasets: PFF (Pine Forests Flora)

The package includes a built-in example dataset called PFF that can be loaded as follows:

    library(MultiTraits)
    data(PFF)
    # View the structure of the datasets
    head(PFF)

    ##                     species      genus      family Height Leaf_area LDMC SLA
    ## 1      Achillea millefolium   Achillea  Asteraceae     14       240   27   8
    ## 2           Agoseris glauca   Agoseris  Asteraceae     12       520   17  20
    ## 3      Agropyron desertorum  Agropyron     Poaceae     26       290   42   9
    ## 4     Ambrosia psilostachya   Ambrosia  Asteraceae     44       490   20  16
    ## 5 Androsace septentrionalis  Androsace Primulaceae      1        51   14  31
    ## 6     Antennaria parvifolia Antennaria  Asteraceae      2        66   27  13
    ##   SRL SeedMass FltDate FltDur k_value Leaf_Cmass Leaf_Nmass Leaf_CN Leaf_Pmass
    ## 1  35    0.140     197    152    1.70      41.16       1.92      22       0.36
    ## 2  56    2.530     213    183    1.10      42.62       1.72      25       0.39
    ## 3  99    0.388     198     91      NA      41.48       2.32      18       0.06
    ## 4  73    5.896     243    122    2.23      38.42       2.32      17       0.25
    ## 5  80    0.128     182    182      NA      40.83       1.95      22       0.29
    ## 6  27    0.061     182    122    0.54      44.07       1.53      30       0.18
    ##   Leaf_NP Leaf_CP Root_Cmass Root_Nmass Root_CN
    ## 1       6     114      40.96       0.48      85
    ## 2       4     109      45.86       0.89      52
    ## 3      52    1021      41.46       1.61      26
    ## 4      14     224      35.69       1.29      28
    ## 5       7     131      46.46       1.23      38
    ## 6       9     252      35.96       0.55      65

The PFF dataset contains trait measurements for plant species found in pine forests, with the following variables:

Height: Maximum plant height (cm)

Leaf_area: Leaf area (mm2)

LDMC: Leaf dry matter content (%)

SLA: Specific leaf area (mm2/mg)

SRL: Specific root length (m/g)

SeedMass: Seed mass (mg)

FltDate: Mean flowering date (Julian day)

FltDur: Mean flowering duration (days)

k_value: Decomposition decay constant, where proportion of original mass remaining = exp(- k-value*0.926)

Leaf_Cmass: Leaf carbon content (%)

Leaf_Nmass: Leaf nitrogen content (%)

Leaf_CN: Leaf carbon/nitrogen ratio

Leaf_Pmass: Leaf phosphorus content (%)

Leaf_NP: Leaf nitrogen/phosphorus ratio

Leaf_CP: Leaf carbon/phosphorus ratio

Root_Cmass: Root carbon content (%)

Root_Nmass: Root nitrogen content (%)

Root_CN: Root carbon/nitrogen ratio

### CSR Strategy

The CSR (Competitor–Stress-Tolerator–Ruderal) strategy, initially conceptualized by Grime (1974), classifies plants based on their ecological strategies, which are influenced by environmental factors such as competition, stress, and disturbance. The MultiTraits package offers two approaches for CSR analysis: the method proposed by Hodgson et al. (1999) and the method developed by Pierce et al. (2017). The Pierce method, used here, employs leaf area (LA), leaf dry matter content (LDMC), and specific leaf area (SLA) to classify species. The CSR_plot() function visualizes the results in a ternary plot, showing species’ positions based on their relative C, S, and R strategy proportions. This aids in understanding plant functional classification and predicting responses to environmental changes.

    # Load packages
    library(MultiTraits)
    # Load the PFF dataset
    data(PFF)
    head(PFF)

    ##                     species      genus      family Height Leaf_area LDMC SLA
    ## 1      Achillea millefolium   Achillea  Asteraceae     14       240   27   8
    ## 2           Agoseris glauca   Agoseris  Asteraceae     12       520   17  20
    ## 3      Agropyron desertorum  Agropyron     Poaceae     26       290   42   9
    ## 4     Ambrosia psilostachya   Ambrosia  Asteraceae     44       490   20  16
    ## 5 Androsace septentrionalis  Androsace Primulaceae      1        51   14  31
    ## 6     Antennaria parvifolia Antennaria  Asteraceae      2        66   27  13
    ##   SRL SeedMass FltDate FltDur k_value Leaf_Cmass Leaf_Nmass Leaf_CN Leaf_Pmass
    ## 1  35    0.140     197    152    1.70      41.16       1.92      22       0.36
    ## 2  56    2.530     213    183    1.10      42.62       1.72      25       0.39
    ## 3  99    0.388     198     91      NA      41.48       2.32      18       0.06
    ## 4  73    5.896     243    122    2.23      38.42       2.32      17       0.25
    ## 5  80    0.128     182    182      NA      40.83       1.95      22       0.29
    ## 6  27    0.061     182    122    0.54      44.07       1.53      30       0.18
    ##   Leaf_NP Leaf_CP Root_Cmass Root_Nmass Root_CN
    ## 1       6     114      40.96       0.48      85
    ## 2       4     109      45.86       0.89      52
    ## 3      52    1021      41.46       1.61      26
    ## 4      14     224      35.69       1.29      28
    ## 5       7     131      46.46       1.23      38
    ## 6       9     252      35.96       0.55      65

    # Create a data frame with the CSR traits
    csr_traits <- data.frame(LA=PFF$Leaf_area, LDMC=PFF$LDMC, SLA=PFF$SLA)
    rownames(csr_traits) <- PFF$species
    head(csr_traits)

    ##                            LA LDMC SLA
    ## Achillea millefolium      240   27   8
    ## Agoseris glauca           520   17  20
    ## Agropyron desertorum      290   42   9
    ## Ambrosia psilostachya     490   20  16
    ## Androsace septentrionalis  51   14  31
    ## Antennaria parvifolia      66   27  13

    # Perform CSR analysis
    csr_result <- CSR(csr_traits)
    head(csr_result)

    ##                            LA LDMC SLA         C         S        R type
    ## Achillea millefolium      240   27   8 18.845244 81.154756  0.00000 S/CS
    ## Agoseris glauca           520   17  20 34.290705  4.542473 61.16682 R/CR
    ## Agropyron desertorum      290   42   9 12.118306 87.881694  0.00000    S
    ## Ambrosia psilostachya     490   20  16 30.293240 30.891427 38.81533  CSR
    ## Androsace septentrionalis  51   14  31  4.068212  0.000000 95.93179    R
    ## Antennaria parvifolia      66   27  13  5.131786 73.958953 20.90926 S/SR

    # Create the CSR plot
    CSR_plot(csr_result)

### LHS Strategy

The Leaf–Height–Seed (LHS) scheme, proposed by Westoby (1998), classifies plant species based on specific leaf area (SLA), canopy height at maturity, and seed mass. These three traits reflect trade-offs in resource acquisition, spatial occupation, and reproductive investment. The MultiTraits package implements the LHS scheme by positioning species in a three-dimensional trait space using log-transformed trait values. This continuous space is then divided into eight discrete strategy types (e.g., S–S–S, L–L–L) based on median trait values, representing different trade-offs in growth, competition, and survival. The LHS_plot() function visualizes these strategies in 3D space, while LHS_strategy_scheme() provides a reference key for interpreting the strategy types.

    # Load packages
    library(MultiTraits)
    # Load the PFF dataset
    data(PFF)
    head(PFF)

    ##                     species      genus      family Height Leaf_area LDMC SLA
    ## 1      Achillea millefolium   Achillea  Asteraceae     14       240   27   8
    ## 2           Agoseris glauca   Agoseris  Asteraceae     12       520   17  20
    ## 3      Agropyron desertorum  Agropyron     Poaceae     26       290   42   9
    ## 4     Ambrosia psilostachya   Ambrosia  Asteraceae     44       490   20  16
    ## 5 Androsace septentrionalis  Androsace Primulaceae      1        51   14  31
    ## 6     Antennaria parvifolia Antennaria  Asteraceae      2        66   27  13
    ##   SRL SeedMass FltDate FltDur k_value Leaf_Cmass Leaf_Nmass Leaf_CN Leaf_Pmass
    ## 1  35    0.140     197    152    1.70      41.16       1.92      22       0.36
    ## 2  56    2.530     213    183    1.10      42.62       1.72      25       0.39
    ## 3  99    0.388     198     91      NA      41.48       2.32      18       0.06
    ## 4  73    5.896     243    122    2.23      38.42       2.32      17       0.25
    ## 5  80    0.128     182    182      NA      40.83       1.95      22       0.29
    ## 6  27    0.061     182    122    0.54      44.07       1.53      30       0.18
    ##   Leaf_NP Leaf_CP Root_Cmass Root_Nmass Root_CN
    ## 1       6     114      40.96       0.48      85
    ## 2       4     109      45.86       0.89      52
    ## 3      52    1021      41.46       1.61      26
    ## 4      14     224      35.69       1.29      28
    ## 5       7     131      46.46       1.23      38
    ## 6       9     252      35.96       0.55      65

    # Create a data frame with the LHS traits
    lhs_traits <- PFF[, c("SLA", "Height", "SeedMass")]
    rownames(lhs_traits) <- PFF$species
    head(lhs_traits)

    ##                           SLA Height SeedMass
    ## Achillea millefolium        8     14    0.140
    ## Agoseris glauca            20     12    2.530
    ## Agropyron desertorum        9     26    0.388
    ## Ambrosia psilostachya      16     44    5.896
    ## Androsace septentrionalis  31      1    0.128
    ## Antennaria parvifolia      13      2    0.061

    # Perform LHS analysis
    lhs_result <- LHS(lhs_traits)
    head(lhs_result)

    ##                           SLA Height SeedMass  log_SLA log_Height log_SeedMass
    ## Achillea millefolium        8     14    0.140 2.079442  2.6390573   -1.9661129
    ## Agoseris glauca            20     12    2.530 2.995732  2.4849066    0.9282193
    ## Agropyron desertorum        9     26    0.388 2.197225  3.2580965   -0.9467499
    ## Ambrosia psilostachya      16     44    5.896 2.772589  3.7841896    1.7742742
    ## Androsace septentrionalis  31      1    0.128 3.433987  0.0000000   -2.0557250
    ## Antennaria parvifolia      13      2    0.061 2.564949  0.6931472   -2.7968814
    ##                           LHS_strategy
    ## Achillea millefolium             S-S-S
    ## Agoseris glauca                  L-S-L
    ## Agropyron desertorum             S-L-S
    ## Ambrosia psilostachya            L-L-L
    ## Androsace septentrionalis        L-S-S
    ## Antennaria parvifolia            S-S-S

    table(lhs_result$LHS_strategy)

    ##
    ## L-L-L L-L-S L-S-L L-S-S S-L-L S-L-S S-S-L S-S-S
    ##    16    18    11    21    20     9    19    19

    # Create a visualization plot of the LHS analysis results
    LHS_plot(lhs_result, group = "LHS_strategy", show_cube = TRUE)

    # Display the LHS strategy scheme diagram
    LHS_strategy_scheme()

    ##    type                                                         strategy
    ## 1 L-L-L           Rapid growth, strong survivability and competitiveness
    ## 2 L-L-S      Rapid growth, strong survivability and weak competitiveness
    ## 3 L-S-L Rapid growth, long-distance dispersal and strong competitiveness
    ## 4 L-S-S   Rapid growth, long-distance dispersal and weak competitiveness
    ## 5 S-L-L            Slow growth, strong survivability and competitiveness
    ## 6 S-L-S       Slow growth, strong survivability and weak competitiveness
    ## 7 S-S-L  Slow growth, long-distance dispersal and strong competitiveness
    ## 8 S-S-S    Slow growth, long-distance dispersal and weak competitiveness

### Niche Periodicity Table

The Niche Periodic Table (NPT) framework systematically describes and predicts species functions by identifying recurring trait combinations driven by convergent evolution. Within the MultiTraits R package, the NPT module offers both discrete and continuous classification schemes. The NPT_discrete() function categorizes species into distinct niche groups using PCA and clustering, with NPT_discrete_plot() visualizing the results. For continuous classification, NPT_continuous() performs hierarchical PCA to create a two-dimensional ordination space, while NPT_continuous_plot() visualizes these integrated niche patterns.

    # Load packages
    library(MultiTraits)
    # 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)

    ##                                SLA      SRL Leaf_Nmass Root_Nmass    Height
    ## Achillea millefolium      2.079442 3.555348  0.6523252 -0.7339692 2.6390573
    ## Agoseris glauca           2.995732 4.025352  0.5423243 -0.1165338 2.4849066
    ## Agropyron desertorum      2.197225 4.595120  0.8415672  0.4762342 3.2580965
    ## Ambrosia psilostachya     2.772589 4.290459  0.8415672  0.2546422 3.7841896
    ## Androsace septentrionalis 3.433987 4.382027  0.6678294  0.2070142 0.0000000
    ## Antennaria parvifolia     2.564949 3.295837  0.4252677 -0.5978370 0.6931472
    ##                            Leaf_CN  Root_CN   SeedMass  FltDate   FltDur
    ## Achillea millefolium      3.091042 4.442651 -1.9661129 5.283204 5.023881
    ## Agoseris glauca           3.218876 3.951244  0.9282193 5.361292 5.209486
    ## Agropyron desertorum      2.890372 3.258097 -0.9467499 5.288267 4.510860
    ## Ambrosia psilostachya     2.833213 3.332205  1.7742742 5.493061 4.804021
    ## Androsace septentrionalis 3.091042 3.637586 -2.0557250 5.204007 5.204007
    ## Antennaria parvifolia     3.401197 4.174387 -2.7968814 5.204007 4.804021

    # 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")
    )

    # Perform discrete niche scheme
    set.seed(123)
    discrete_result <- NPT_discrete(data = PFF_traits, dimension = dimension)

    ## === PCA Analysis Results ===
    ## Dimension: Grow
    ## PC1 variance explained: 51.38 %
    ## PC2 variance explained: 31.01 %
    ##
    ## Dimension: Survive
    ## PC1 variance explained: 80.24 %
    ## PC2 variance explained: 15.45 %
    ##
    ## Dimension: Reproductive
    ## PC1 variance explained: 94.75 %
    ## PC2 variance explained: 4.5 %
    ##
    ## ===  CART  Clustering Results ===
    ## Dimension Grow cluster count: 8
    ## Dimension Survive cluster count: 8
    ## Dimension Reproductive cluster count: 8
    ##
    ## === Niche Classification Results ===
    ## Total potential niches: 512
    ## Actual occupied niches: 99
    ## Niche occupancy rate: 19.34 %

    discrete_result

    ## $niche_classification
    ##                        species Grow Survive Reproductive niche_code
    ## 1         Achillea millefolium    7       1            2      7,1,2
    ## 2              Agoseris glauca    1       1            5      1,1,5
    ## 3         Agropyron desertorum    4       2            3      4,2,3
    ## 4        Ambrosia psilostachya    1       2            4      1,2,4
    ## 5    Androsace septentrionalis    4       8            6      4,8,6
    ## 6        Antennaria parvifolia    3       8            6      3,8,6
    ## 7          Antennaria rosulata    3       8            6      3,8,6
    ## 8            Arenaria fendleri    1       1            5      1,1,5
    ## 9          Arenaria lanuginosa    3       1            2      3,1,2
    ## 10           Aristida purpurea    7       5            5      7,5,5
    ## 11        Artemisia campestris    1       2            6      1,2,6
    ## 12         Artemisia carruthii    1       2            6      1,2,6
    ## 13       Artemisia dracunculus    4       6            6      4,6,6
    ## 14      Astragalus humistratus    3       7            2      3,7,2
    ## 15           Astragalus rusbyi    8       7            1      8,7,1
    ## 16              Bahia dissecta    4       6            3      4,6,3
    ## 17  Blepharoneuron tricholepis    7       5            1      7,5,1
    ## 18      Bouteloua curtipendula    4       5            5      4,5,5
    ## 19          Bouteloua gracilis    4       2            1      4,2,1
    ## 20           Bouteloua simplex    6       1            8      6,1,8
    ## 21             Bromus ciliatus    1       2            4      1,2,4
    ## 22             Bromus tectorum    3       1            8      3,1,8
    ## 23              Carex geophila    3       5            3      3,5,3
    ## 24    Castilleja austromontana    5       2            2      5,2,2
    ## 25          Castilleja integra    5       1            6      5,1,6
    ## 26          Ceanothus fendleri    1       1            4      1,1,4
    ## 27           Centaurea diffusa    1       2            3      1,2,3
    ## 28       Chaetopappa ericoides    1       1            5      1,1,5
    ## 29         Chamaesyce fendleri    4       5            6      4,5,6
    ## 30    Chamaesyce serpyllifolia    6       8            5      6,8,5
    ## 31       Chenopodium fremontii    8       6            1      8,6,1
    ## 32      Chenopodium graveolens    8       7            8      8,7,8
    ## 33            Cirsium wheeleri    5       6            7      5,6,7
    ## 34        Convolvulus arvensis    3       4            7      3,4,7
    ## 35         Coreopsis tinctoria    3       1            1      3,1,1
    ## 36          Cosmos parviflorus    8       3            4      8,3,4
    ## 37             Draba asperella    1       8            6      1,8,6
    ## 38        Drymaria leptophylla    6       8            8      6,8,8
    ## 39         Drymaria molluginea    7       8            8      7,8,8
    ## 40        Echeandia flavescens    4       1            8      4,1,8
    ## 41            Elymus elymoides    1       2            4      1,2,4
    ## 42         Elymus trachycaulus    2       5            4      2,5,4
    ## 43      Epilobium brachycarpum    4       3            8      4,3,8
    ## 44         Eragrostis mexicana    6       1            3      6,1,3
    ## 45          Erigeron divergens    3       1            6      3,1,6
    ## 46         Erigeron flavescens    1       8            6      1,8,6
    ## 47      Erigeron formosissimus    1       1            3      1,1,3
    ## 48           Erigeron speciosa    3       2            3      3,2,3
    ## 49            Eriogonum alatum    7       1            4      7,1,4
    ## 50     Eriogonum pharnaceoides    1       1            1      1,1,1
    ## 51         Eriogonum racemosum    2       4            2      2,4,2
    ## 52          Erodium cicutarium    8       8            2      8,8,2
    ## 53               Euphorbia sp.    5       1            4      5,1,4
    ## 54           Festuca arizonica    2       5            3      2,5,3
    ## 55      Gaillardia pinnatifida    1       4            2      1,4,2
    ## 56        Geranium caespitosum    5       1            5      5,1,5
    ## 57       Geranium richardsonii    1       1            5      1,1,5
    ## 58       Gutierrezia sarothrae    4       1            2      4,1,2
    ## 59       Heliomeris multiflora    4       3            5      4,3,5
    ## 60  Helianthella quinquinervis    5       2            7      5,2,7
    ## 61         Hesperostipa comata    7       5            7      7,5,7
    ## 62         Heterotheca villosa    1       1            5      1,1,5
    ## 63          Hieracium fendleri    2       4            1      2,4,1
    ## 64          Houstonia wrightii    3       8            8      3,8,8
    ## 65           Hymenoxys hoopsii    1       6            1      1,6,1
    ## 66      Hymenoxys richardsonii    1       1            2      1,1,2
    ## 67      Hymenopappus mexicanus    3       1            1      3,1,1
    ## 68         Ipomopsis aggregata    2       2            2      2,2,2
    ## 69        Ipomopsis multiflora    1       1            1      1,1,1
    ## 70          Iris missouriensis    5       2            7      5,2,7
    ## 71          Koeleria macrantha    2       1            6      2,1,6
    ## 72        Laennecia schiedeana    1       2            6      1,2,6
    ## 73        Lepidium densiflorum    8       3            2      8,3,2
    ## 74              Linum australe    1       1            3      1,1,3
    ## 75               Linum lewisii    3       2            5      3,2,5
    ## 76           Linaria dalmatica    3       6            8      3,6,8
    ## 77    Lithospermum multiflorum    5       2            4      5,2,4
    ## 78              Lotus wrightii    8       7            4      8,7,4
    ## 79           Lupinus argenteus    8       7            7      8,7,7
    ## 80              Lupinus kingii    8       7            7      8,7,7
    ## 81    Machaeranthera canescens    1       2            5      1,2,5
    ## 82     Machaeranthera gracilis    4       1            5      4,1,5
    ## 83         Mirabilis decipiens    8       3            4      8,3,4
    ## 84            Monroa squarrosa    4       4            2      4,4,2
    ## 85    Muhlenbergia minutissima    6       1            6      6,1,6
    ## 86        Muhlenbergia montana    7       5            3      7,5,3
    ## 87       Muhlenbergia ramulosa    7       1            8      7,1,8
    ## 88         Muhlenbergia rigens    7       5            6      7,5,6
    ## 89       Muhlenbergia wrightii    4       2            1      4,2,1
    ## 90             Nama dichotomum    8       3            8      8,3,8
    ## 91             Noccaea montana    1       8            5      1,8,5
    ## 92         Oenothera pubescens    4       1            1      4,1,1
    ## 93                  Oxalis sp.    8       8            3      8,8,3
    ## 94         Oxytropis lambertii    8       7            5      8,7,5
    ## 95         Packera multilobata    3       1            5      3,1,5
    ## 96          Pascopyrum smithii    3       6            4      3,6,4
    ## 97          Penstemon barbatus    3       2            8      3,2,8
    ## 98          Penstemon linearis    7       5            1      7,5,1
    ## 99          Penstemon virgatus    3       2            1      3,2,1
    ## 100             Phlox speciosa    3       4            3      3,4,3
    ## 101            Pinus ponderosa    7       6            8      7,6,8
    ## 102          Plantago argyraea    4       1            1      4,1,1
    ## 103              Poa compressa    2       5            5      2,5,5
    ## 104            Poa fendleriana    7       5            2      7,5,2
    ## 105              Poa pratensis    1       2            6      1,2,6
    ## 106        Polygonum aviculare    4       7            5      4,7,5
    ## 107        Polygonum douglasii    4       1            1      4,1,1
    ## 108         Portulaca oleracea    6       8            6      6,8,6
    ## 109         Potentilla crinita    2       4            5      2,4,5
    ## 110        Potentilla hippiana    5       1            1      5,1,1
    ## 111      Potentilla subviscosa    2       8            1      2,8,1
    ## 112  Pseudognaphalium macounii    6       1            6      6,1,6
    ## 113        Cymopterus lemmonii    5       1            5      5,1,5
    ## 114           Quercus gambelii    5       6            8      5,6,8
    ## 115               Rosa woodsii    3       5            4      3,5,4
    ## 116             Salsola tragus    8       7            1      8,7,1
    ## 117    Schizachyrium scoparium    4       6            3      4,6,3
    ## 118          Senecio actinella    2       4            1      2,4,1
    ## 119        Senecio eremophilis    8       6            1      8,6,1
    ## 120              Solidago nana    4       5            3      4,5,3
    ## 121          Solidago velutina    3       2            2      3,2,2
    ## 122     Sporobolus interruptus    4       5            3      4,5,3
    ## 123   Symphyotrichum ascendens    1       1            1      1,1,1
    ## 124       Taraxacum officinale    8       3            5      8,3,5
    ## 125        Thalictrum fendleri    3       6            4      3,6,4
    ## 126         Townsendia exscapa    1       8            3      1,8,3
    ## 127          Tragopogon dubius    1       2            4      1,2,4
    ## 128         Trifolium longipes    8       4            2      8,4,2
    ## 129          Verbena bracteata    1       1            2      1,1,2
    ## 130          Verbascum thapsus    1       6            6      1,6,6
    ## 131            Vicia americana    8       7            7      8,7,7
    ## 132            Vicia pulchella    8       7            7      8,7,7
    ## 133           Viola canadensis    2       1            5      2,1,5
    ##
    ## $summary
    ## # A tibble: 99 × 3
    ##    niche_code species_count species_list
    ##    <chr>              <int> <chr>
    ##  1 1,1,1                  3 Eriogonum pharnaceoides, Ipomopsis multiflora, Symp…
    ##  2 1,1,2                  2 Hymenoxys richardsonii, Verbena bracteata
    ##  3 1,1,3                  2 Erigeron formosissimus, Linum australe
    ##  4 1,1,4                  1 Ceanothus fendleri
    ##  5 1,1,5                  5 Agoseris glauca, Arenaria fendleri, Chaetopappa eri…
    ##  6 1,2,3                  1 Centaurea diffusa
    ##  7 1,2,4                  4 Ambrosia psilostachya, Bromus ciliatus, Elymus elym…
    ##  8 1,2,5                  1 Machaeranthera canescens
    ##  9 1,2,6                  4 Artemisia campestris, Artemisia carruthii, Laenneci…
    ## 10 1,4,2                  1 Gaillardia pinnatifida
    ## # ℹ 89 more rows

    NPT_discrete_plot(discrete_result$niche_classification)

    # Perform continuous niche scheme
    continuous_result <- NPT_continuous(data = PFF_traits, dimension = dimension)
    continuous_result

    ## $PCA_first
    ##              pc1_percent pc1_major_eigenvector pc2_percent
    ## Grow            51.37787                   SRL    31.00776
    ## Survive         80.23625                Height    15.44795
    ## Reproductive    94.74834              SeedMass     4.49701
    ##              pc2_major_eigenvector
    ## Grow                    Leaf_Nmass
    ## Survive                    Root_CN
    ## Reproductive                FltDur
    ##
    ## $PCA_second
    ##                         PC1        PC2
    ## pc1.Grow          0.1089647 -0.5590265
    ## pc2.Grow          0.6488371  0.1751767
    ## pc1.Survive      -0.1162702  0.5380610
    ## pc2.Survive      -0.6329334 -0.2313366
    ## pc1.Reproductive -0.3185430  0.5385830
    ## pc2.Reproductive  0.2270331  0.1539628
    ##
    ## $result
    ## Call: rda(X = P)
    ##
    ## -- Model Summary --
    ##
    ##               Inertia Rank
    ## Total         0.04545
    ## Unconstrained 0.04545    6
    ##
    ## Inertia is variance
    ##
    ## -- Eigenvalues --
    ##
    ## Eigenvalues for unconstrained axes:
    ##      PC1      PC2      PC3      PC4      PC5      PC6
    ## 0.015689 0.012709 0.008295 0.004579 0.003609 0.000573

    NPT_continuous_plot(continuous_result$result)

### Plant Trait Network

Plant Trait Networks (PTNs) provide a framework for understanding complex interdependencies among plant traits by treating traits as nodes and their associations as edges within a network. The PTN module, implemented as described by He et al. (2020), offers functions to calculate correlations (PTN_corr()), generate networks (PTN()), quantify network metrics (PTN_metrics()), and visualize networks (PTN_plot()). The package supports phylogenetic correction to account for species’ shared evolutionary history. Significant correlations are selected based on defined thresholds, and network metrics, including both node-level and network-level parameters, are used to analyze trait interdependence.

    # Load packages
    library(MultiTraits)
    # Load and prepare data
    data(PFF)
    rownames(PFF) <- PFF$species
    PFF_traits <- PFF[, c("Leaf_area","LDMC","SLA", "Leaf_Cmass","Leaf_Nmass",
                          "Leaf_CN","Leaf_Pmass", "Leaf_NP","Leaf_CP")]
    # Perform log transformation of data and remove missing values
    PFF_traits <- log(na.omit(PFF_traits))
    head(PFF_traits)

    ##                           Leaf_area     LDMC      SLA Leaf_Cmass Leaf_Nmass
    ## Achillea millefolium       5.480639 3.295837 2.079442   3.717467  0.6523252
    ## Agoseris glauca            6.253829 2.833213 2.995732   3.752324  0.5423243
    ## Agropyron desertorum       5.669881 3.737670 2.197225   3.725211  0.8415672
    ## Ambrosia psilostachya      6.194405 2.995732 2.772589   3.648578  0.8415672
    ## Androsace septentrionalis  3.931826 2.639057 3.433987   3.709417  0.6678294
    ## Antennaria parvifolia      4.189655 3.295837 2.564949   3.785779  0.4252677
    ##                            Leaf_CN Leaf_Pmass  Leaf_NP  Leaf_CP
    ## Achillea millefolium      3.091042 -1.0216512 1.791759 4.736198
    ## Agoseris glauca           3.218876 -0.9416085 1.386294 4.691348
    ## Agropyron desertorum      2.890372 -2.8134107 3.951244 6.928538
    ## Ambrosia psilostachya     2.833213 -1.3862944 2.639057 5.411646
    ## Androsace septentrionalis 3.091042 -1.2378744 1.945910 4.875197
    ## Antennaria parvifolia     3.401197 -1.7147984 2.197225 5.529429

    data(PFF_tree)
    PFF_tree

    ##
    ## Phylogenetic tree with 133 tips and 121 internal nodes.
    ##
    ## Tip labels:
    ##   Hymenopappus mexicanus, Heliomeris multiflora, Bahia dissecta, Gaillardia pinnatifida, Hymenoxys richardsonii, Hymenoxys hoopsii, ...
    ## Node labels:
    ##   Spermatophyta, mrcaott2ott121, eudicotyledons, Pentapetalae, mrcaott248ott557, mrcaott248ott650, ...
    ##
    ## Rooted; includes branch length(s).

    # Calculate trait correlations using specified thresholds
    PTN_corr(traits_matrix=PFF_traits, rThres = 0.2, pThres = 0.05,method = "pearson",
             phylo_correction = TRUE,phylo_tree = PFF_tree)

    ## Warning: Phylogenetic tree is not binary. Converting to binary tree using multi2di()...
    ## Tree converted to binary successfully.

    ## $corr
    ##             Leaf_area  Leaf_Pmass         SLA  Leaf_Nmass    Leaf_CN
    ## Leaf_area   1.0000000  0.43912732  0.07106310  0.29303640 -0.2770506
    ## Leaf_Pmass  0.4391273  1.00000000  0.12060634  0.18114586 -0.1622283
    ## SLA         0.0710631  0.12060634  1.00000000  0.26196776 -0.3165084
    ## Leaf_Nmass  0.2930364  0.18114586  0.26196776  1.00000000 -0.9761786
    ## Leaf_CN    -0.2770506 -0.16222829 -0.31650840 -0.97617860  1.0000000
    ## Leaf_NP    -0.1850404 -0.81553086 -0.02961639  0.26587312 -0.2712585
    ## Leaf_CP    -0.3384473 -0.90624588 -0.17882705 -0.18159881  0.1847273
    ## LDMC       -0.0586106 -0.21033983 -0.53223724 -0.06763656  0.1264002
    ## Leaf_Cmass  0.1708826 -0.05369696 -0.26471993  0.32997265 -0.1559343
    ##                Leaf_NP    Leaf_CP        LDMC  Leaf_Cmass
    ## Leaf_area  -0.18504037 -0.3384473 -0.05861060  0.17088257
    ## Leaf_Pmass -0.81553086 -0.9062459 -0.21033983 -0.05369696
    ## SLA        -0.02961639 -0.1788270 -0.53223724 -0.26471993
    ## Leaf_Nmass  0.26587312 -0.1815988 -0.06763656  0.32997265
    ## Leaf_CN    -0.27125855  0.1847273  0.12640024 -0.15593428
    ## Leaf_NP     1.00000000  0.8903621  0.19732960  0.24660715
    ## Leaf_CP     0.89036211  1.0000000  0.28270267  0.17686543
    ## LDMC        0.19732960  0.2827027  1.00000000  0.37675591
    ## Leaf_Cmass  0.24660715  0.1768654  0.37675591  1.00000000
    ##
    ## $corrPos
    ##         xName      yName x y        corr p.value
    ## 1   Leaf_area Leaf_Pmass 1 8  0.43912732       0
    ## 2   Leaf_area        SLA 1 7  0.07106310       1
    ## 3   Leaf_area Leaf_Nmass 1 6  0.29303640       0
    ## 4   Leaf_area    Leaf_CN 1 5 -0.27705059       0
    ## 5   Leaf_area    Leaf_NP 1 4 -0.18504037       1
    ## 6   Leaf_area    Leaf_CP 1 3 -0.33844728       0
    ## 7   Leaf_area       LDMC 1 2 -0.05861060       1
    ## 8   Leaf_area Leaf_Cmass 1 1  0.17088257       1
    ## 9  Leaf_Pmass        SLA 2 7  0.12060634       1
    ## 10 Leaf_Pmass Leaf_Nmass 2 6  0.18114586       1
    ## 11 Leaf_Pmass    Leaf_CN 2 5 -0.16222829       1
    ## 12 Leaf_Pmass    Leaf_NP 2 4 -0.81553086       0
    ## 13 Leaf_Pmass    Leaf_CP 2 3 -0.90624588       0
    ## 14 Leaf_Pmass       LDMC 2 2 -0.21033983       0
    ## 15 Leaf_Pmass Leaf_Cmass 2 1 -0.05369696       1
    ## 16        SLA Leaf_Nmass 3 6  0.26196776       0
    ## 17        SLA    Leaf_CN 3 5 -0.31650840       0
    ## 18        SLA    Leaf_NP 3 4 -0.02961639       1
    ## 19        SLA    Leaf_CP 3 3 -0.17882705       1
    ## 20        SLA       LDMC 3 2 -0.53223724       0
    ## 21        SLA Leaf_Cmass 3 1 -0.26471993       0
    ## 22 Leaf_Nmass    Leaf_CN 4 5 -0.97617860       0
    ## 23 Leaf_Nmass    Leaf_NP 4 4  0.26587312       0
    ## 24 Leaf_Nmass    Leaf_CP 4 3 -0.18159881       1
    ## 25 Leaf_Nmass       LDMC 4 2 -0.06763656       1
    ## 26 Leaf_Nmass Leaf_Cmass 4 1  0.32997265       0
    ## 27    Leaf_CN    Leaf_NP 5 4 -0.27125855       0
    ## 28    Leaf_CN    Leaf_CP 5 3  0.18472730       1
    ## 29    Leaf_CN       LDMC 5 2  0.12640024       1
    ## 30    Leaf_CN Leaf_Cmass 5 1 -0.15593428       1
    ## 31    Leaf_NP    Leaf_CP 6 3  0.89036211       0
    ## 32    Leaf_NP       LDMC 6 2  0.19732960       1
    ## 33    Leaf_NP Leaf_Cmass 6 1  0.24660715       0
    ## 34    Leaf_CP       LDMC 7 2  0.28270267       0
    ## 35    Leaf_CP Leaf_Cmass 7 1  0.17686543       1
    ## 36       LDMC Leaf_Cmass 8 1  0.37675591       0
    ##
    ## $arg
    ## $arg$type
    ## [1] "lower"

    # Perform Trait Network (TN) analysis
    PTN_phylo_result <- PTN(traits_matrix = PFF_traits,
                          rThres = 0.2,
                          pThres = 0.05,
                          method = "pearson",
                          phylo_correction = TRUE,
                          phylo_tree = PFF_tree)

    ## Warning: Phylogenetic tree is not binary. Converting to binary tree using multi2di()...
    ## Tree converted to binary successfully.

    # Calculate network metrics for the trait network
    PTN_metrics(PTN_phylo_result)

    ## $node
    ##            degree  closeness betweenness clustering_coefficient
    ## Leaf_area       4 0.08333333    2.000000              0.3333333
    ## LDMC            4 0.08333333    3.000000              0.3333333
    ## SLA             4 0.08333333    1.833333              0.5000000
    ## Leaf_Cmass      4 0.08333333    1.166667              0.5000000
    ## Leaf_Nmass      5 0.09090909    2.416667              0.5000000
    ## Leaf_CN         4 0.08333333    1.083333              0.5000000
    ## Leaf_Pmass      4 0.08333333    1.083333              0.5000000
    ## Leaf_NP         5 0.09090909    3.333333              0.3000000
    ## Leaf_CP         4 0.08333333    1.083333              0.5000000
    ##
    ## $global
    ##   edge_density diameter avg_path_length avg_clustering_coefficient modularity
    ## 1    0.5277778        2        1.472222                  0.4354839  0.1717452

    set.seed(22)
    # Create visualization plots of the trait network
    PTN_plot(PTN_phylo_result, style = 1, vertex.size = 20, vertex.label.cex = 0.6)