library(phytools)
## Loading required package: ape
## Loading required package: maps
library(kableExtra)
library(phangorn)
library(ape)
# if (!require("BiocManager", quietly = TRUE))
#     install.packages("BiocManager")
# BiocManager::install("ggtree")
#library(ggtree)

tree<- read.tree("~/Dropbox/FCU/Teaching/Mentoring/2016Spring-2021Fall_AssociateProfessor/2020Fall/ChiYuWu/rcodeCYW/mammal2.nwk")

plot(tree)

df<-read.csv("~/Dropbox/FCU/Teaching/Mentoring/2016Spring-2021Fall_AssociateProfessor/2020Fall/ChiYuWu/dataset/capellini2015role.csv")
head(df,30)
##                    Binomial Intro Est Spread NoLocs   LG       BM    GT     WA
## 1    Tachyglossus_aculeatus     1   1     NA      3 50.0  4499.97 17.72 170.08
## 2  Ornithorhynchus_anatinus     1   1     NA      2 22.6  1484.25 12.48 120.97
## 3     Didelphis_marsupialis     1   1      1      6  4.2  1134.75 14.00  92.47
## 4    Parantechinus_apicalis     1  NA     NA      1  5.5    71.31 48.50 112.70
## 5    Perameles_bougainville     0  NA     NA     NA  5.8   230.80 12.00  61.00
## 6          Perameles_gunnii     0  NA     NA     NA  6.1   903.46 12.50  59.99
## 7           Isoodon_auratus     1  NA     NA      1  6.7   425.00 12.00     NA
## 8          Isoodon_obesulus     1   0     NA      1  6.5   824.76 15.00  59.99
## 9          Macrotis_lagotis     1  NA     NA      1 10.0  1229.58 14.60  93.73
## 10   Phascolarctos_cinereus     1   1     NA     20 22.1  6528.74 34.29 347.53
## 11    Lasiorhinus_latifrons     1   1     NA      2 29.9 26163.80 20.74 326.07
## 12         Vombatus_ursinus     1  NA     NA      1 30.0 26000.00 30.00 447.45
## 13    Trichosurus_vulpecula     1   1      1     36 15.9  2685.39 17.50 191.59
## 14    Spilocuscus_maculatus     1   1      0      2 17.0  4060.46 12.99 240.75
## 15     Phalanger_orientalis     1   1     NA     14  4.0  2487.50    NA     NA
## 16       Petaurus_breviceps     1   1      1      1 17.8   120.76 16.68 118.65
## 17 Pseudocheirus_peregrinus     1   1     NA      3 10.1   895.22    NA 197.14
## 18     Potorous_tridactylus     1   0     NA      2 14.5  1054.67 33.55 167.33
## 19       Bettongia_gaimardi     1   1     NA      1 11.8  1667.55 21.14 121.32
## 20        Bettongia_lesueur     1   1      0      1 10.0  1447.27 21.28 164.53
## 21    Bettongia_penicillata     1   1     NA      1 18.8  1184.35 20.35 150.00
## 22    Lagorchestes_hirsutus     1  NA     NA      1 13.2  1407.14 30.00 150.00
## 23   Thylogale_billardierii     0  NA     NA     NA 10.0  5865.86 30.73 289.17
## 24         Thylogale_browni     1   1     NA      6   NA  5478.00    NA     NA
## 25      Petrogale_lateralis     1   1     NA      5 12.0  4567.88    NA     NA
## 26    Petrogale_penicillata     1   1      0      4 14.4  6931.60 30.99 290.00
## 27          Macropus_agilis     1   0     NA      2 16.9 11815.75 30.51 321.74
## 28        Macropus_dorsalis     0  NA     NA     NA 15.0 11249.96 34.98 335.00
## 29         Macropus_eugenii     1   1      0      6 15.1  5278.48 29.89 315.00
## 30     Macropus_fuliginosus     1   1     NA      2 23.2 25564.70 30.80 518.67
##       NBM   LS     LY       AFB        RL          OV
## 1    0.37 1.00 0.5000 2799.5500 15450.450 0.047247815
## 2      NA 2.00 1.0000  730.0000  7519.000 0.048543689
## 3    0.16 7.09 2.0000  182.5000  1350.500 0.135135135
## 4      NA 7.50 1.0000        NA        NA        <NA>
## 5      NA 2.00 2.0000        NA        NA        <NA>
## 6    0.22 2.31 3.8000  121.7472  2104.753 0.045636063
## 7      NA 2.60     NA        NA        NA        <NA>
## 8    0.34 2.33 2.2000        NA        NA        <NA>
## 9      NA 1.50 4.0000  182.6208  3467.379 0.026316706
## 10   0.36 1.01 1.0000  730.0000  7336.500 0.049751244
## 11   0.49 1.00 1.0000 2737.5000  8176.000 0.044642857
## 12   0.49 1.00 0.5000        NA        NA        <NA>
## 13   0.20 1.02 1.5000  547.5000  5256.000 0.046296296
## 14     NA 1.26 1.0000        NA        NA        <NA>
## 15     NA 1.71     NA        NA        NA        <NA>
## 16   0.18 1.82 1.3000  403.0200  6093.980 0.046073212
## 17   0.29 1.89 1.5000  365.0000  3321.500 0.073260073
## 18   0.31 1.00 2.0000  399.2100  4893.290 0.037295971
## 19   0.30 1.00 3.2500  272.0000  4035.000 0.027833381
## 20   0.31 1.00 3.0000  206.4500  3443.550 0.035331756
## 21   0.28 1.00 3.0000  288.9500  6573.050 0.018509926
## 22     NA 1.00 2.9200        NA        NA        <NA>
## 23   0.40 1.00 1.0000  441.0400  3208.960 0.113744017
## 24     NA 1.02     NA        NA        NA        <NA>
## 25     NA 1.00     NA        NA        NA        <NA>
## 26 103.00 1.00 1.8250        NA        NA        <NA>
## 27   0.63 1.01 1.8000  410.6200  5757.880 0.035217437
## 28   0.75 1.00 1.7299        NA        NA        <NA>
## 29   0.44 1.01 1.0000  319.3700  5192.130 0.070298702
## 30   0.86 1.00 1.0000  608.3300  7859.670 0.046439609