1 Packages and data

Load packages and read in datasets for class exercises:

lfish <- read.csv(file =  "data/fishcoms_lizardisland.csv")

2 Exercise 1

The “fishcoms_lizardisland.csv” dataset includes counts of reef fishes at fourteen sites around Lizard Island, Australia. The sites are shown in the map below.


The sites are marked with symbols, indicating different regimes of wave action. The regimes of wave action include exposed, oblique, sheltered, and lagoon, and they may impact reef fish community composition. The data were collected by divers that ran transects at two distinct depths to survey fishes at each site. For simplicity in this exercise, we will focus on a single family, Pomacentridae, which are commonly known as damselfishes.


2.1 Part I

  1. Filter the families to only retain members of the Pomacentridae.
  2. Calculate the sum of individuals (abundance) of each species at each site across exposure regimes. This should yield a dataset with 389 rows and 4 columns.
  3. Spread the data into a wide format, using the spread() function. There will be lots of “NAs.” Get rid of the NAs using the term “fill = 0” inside the spread() function.
# filter Pomacentridae and calculate the abundance of each species
lizard.sum <- lfish %>%
  filter(Family == "Pomacentridae") %>%
  group_by(Site, Exposure, species) %>%
  summarize(abundance = sum(abundance))
## `summarise()` has grouped output by 'Site', 'Exposure'. You can override using
## the `.groups` argument.
lizard.sum
## # A tibble: 389 × 4
## # Groups:   Site, Exposure [14]
##    Site       Exposure  species  abundance
##    <chr>      <chr>     <chr>        <int>
##  1 Big Vickis Sheltered abu.whit         4
##  2 Big Vickis Sheltered acn.poly        23
##  3 Big Vickis Sheltered amb.cura        57
##  4 Big Vickis Sheltered amb.leuc         7
##  5 Big Vickis Sheltered amp.akin         3
##  6 Big Vickis Sheltered amp.clar         3
##  7 Big Vickis Sheltered chr.alis        12
##  8 Big Vickis Sheltered chr.tern       291
##  9 Big Vickis Sheltered chr.viri        79
## 10 Big Vickis Sheltered chy.roll        12
## # … with 379 more rows
# spread into wide format and get rid of NAs
lizard.wide <- lizard.sum %>%
  spread(key = species, value = abundance, fill = 0)
lizard.wide
## # A tibble: 14 × 57
## # Groups:   Site, Exposure [14]
##    Site  Expos…¹ abu.s…² abu.w…³ acn.p…⁴ amb.a…⁵ amb.c…⁶ amb.l…⁷ amp.a…⁸ amp.c…⁹
##    <chr> <chr>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
##  1 Big … Shelte…       0       4      23       0      57       7       3       3
##  2 Blue… Lagoon        4       0      35       0     307       1       0       0
##  3 Bomm… Oblique       0       0      62       0      57      21       0       0
##  4 Coco… Exposed       0      45     181       0      64      13       0       0
##  5 Gran… Shelte…       1       0       9       0       1       0       0       1
##  6 LTMP1 Exposed       1     268      72       0      54      19       0       0
##  7 LTMP3 Exposed       0      43     182       1      72      18       4       0
##  8 Monk… Lagoon        0       0       1       0      82      33       0       0
##  9 Nort… Shelte…       0       0      55       0      23       2       2       0
## 10 Palf… Lagoon        0       0      77       0     192       0       0       0
## 11 Pidg… Exposed       0       0     118       0      47      14       0       0
## 12 Reso… Shelte…       0       0      29       0       1       0       2       4
## 13 Stev… Oblique       0       0      23       0      44       7       1       1
## 14 Wash… Oblique       0       0      39       0      18       0       0       0
## # … with 47 more variables: amp.mela <dbl>, amp.peri <dbl>, chr.alis <dbl>,
## #   chr.lepi <dbl>, chr.marg <dbl>, chr.tern <dbl>, chr.viri <dbl>,
## #   chr.webe <dbl>, chr.xant <dbl>, chy.cyan <dbl>, chy.flav <dbl>,
## #   chy.rex <dbl>, chy.roll <dbl>, chy.talb <dbl>, das.arua <dbl>,
## #   das.reti <dbl>, das.trim <dbl>, dis.mela <dbl>, dis.pers <dbl>,
## #   dis.pros <dbl>, dis.pseu <dbl>, hgy.plag <dbl>, neg.mela <dbl>,
## #   neg.nigr <dbl>, neo.azys <dbl>, neo.cyan <dbl>, pgy.dick <dbl>, …

2.2 Part II

  1. Split your dataset into metadata (site and exposure information) and numeric data.
  2. Run a PCA and view the summary. Note the percent variation explained by PC1 and PC2.
# isolate metadata
lizard.meta <- lizard.wide[1:2]
lizard.meta
## # A tibble: 14 × 2
## # Groups:   Site, Exposure [14]
##    Site            Exposure 
##    <chr>           <chr>    
##  1 Big Vickis      Sheltered
##  2 Blue Lagoon     Lagoon   
##  3 Bommie Bay      Oblique  
##  4 Coconut         Exposed  
##  5 Granite         Sheltered
##  6 LTMP1           Exposed  
##  7 LTMP3           Exposed  
##  8 Monkey's Butt   Lagoon   
##  9 North Reef      Sheltered
## 10 Palfrey Lagoon  Lagoon   
## 11 Pidgin Point    Exposed  
## 12 Resort          Sheltered
## 13 Steve's Gully   Oblique  
## 14 Washing Machine Oblique
# isolate numeric data
lizard.raw <- lizard.wide %>%
  ungroup() %>%
  select(-c(1:2))
lizard.raw
## # A tibble: 14 × 55
##    abu.sexs abu.whit acn.poly amb.aure amb.cura amb.leuc amp.a…¹ amp.c…² amp.m…³
##       <dbl>    <dbl>    <dbl>    <dbl>    <dbl>    <dbl>   <dbl>   <dbl>   <dbl>
##  1        0        4       23        0       57        7       3       3       0
##  2        4        0       35        0      307        1       0       0       0
##  3        0        0       62        0       57       21       0       0       4
##  4        0       45      181        0       64       13       0       0       0
##  5        1        0        9        0        1        0       0       1       0
##  6        1      268       72        0       54       19       0       0       0
##  7        0       43      182        1       72       18       4       0       0
##  8        0        0        1        0       82       33       0       0       0
##  9        0        0       55        0       23        2       2       0       0
## 10        0        0       77        0      192        0       0       0       0
## 11        0        0      118        0       47       14       0       0       0
## 12        0        0       29        0        1        0       2       4       0
## 13        0        0       23        0       44        7       1       1       0
## 14        0        0       39        0       18        0       0       0       0
## # … with 46 more variables: amp.peri <dbl>, chr.alis <dbl>, chr.lepi <dbl>,
## #   chr.marg <dbl>, chr.tern <dbl>, chr.viri <dbl>, chr.webe <dbl>,
## #   chr.xant <dbl>, chy.cyan <dbl>, chy.flav <dbl>, chy.rex <dbl>,
## #   chy.roll <dbl>, chy.talb <dbl>, das.arua <dbl>, das.reti <dbl>,
## #   das.trim <dbl>, dis.mela <dbl>, dis.pers <dbl>, dis.pros <dbl>,
## #   dis.pseu <dbl>, hgy.plag <dbl>, neg.mela <dbl>, neg.nigr <dbl>,
## #   neo.azys <dbl>, neo.cyan <dbl>, pgy.dick <dbl>, pgy.lacr <dbl>, …
# run PCA and view summary
lizard.pca <- summary(rda(lizard.raw, scale = T))
lizard.pca
## 
## Call:
## rda(X = lizard.raw, scale = T) 
## 
## Partitioning of correlations:
##               Inertia Proportion
## Total              55          1
## Unconstrained      55          1
## 
## Eigenvalues, and their contribution to the correlations 
## 
## Importance of components:
##                           PC1    PC2    PC3     PC4     PC5     PC6     PC7
## Eigenvalue            11.9775 8.5486 6.1300 5.24090 4.55776 3.86037 3.44810
## Proportion Explained   0.2178 0.1554 0.1115 0.09529 0.08287 0.07019 0.06269
## Cumulative Proportion  0.2178 0.3732 0.4847 0.57995 0.66281 0.73300 0.79570
##                           PC8     PC9    PC10    PC11    PC12    PC13
## Eigenvalue            2.72451 2.68263 2.45025 1.40725 1.14087 0.83126
## Proportion Explained  0.04954 0.04878 0.04455 0.02559 0.02074 0.01511
## Cumulative Proportion 0.84523 0.89401 0.93856 0.96414 0.98489 1.00000
## 
## Scaling 2 for species and site scores
## * Species are scaled proportional to eigenvalues
## * Sites are unscaled: weighted dispersion equal on all dimensions
## * General scaling constant of scores:  5.171023 
## 
## 
## Species scores
## 
##               PC1      PC2       PC3       PC4       PC5       PC6
## abu.sexs -0.28419 -0.26752 -0.059225 -0.307390  0.337479  0.033509
## abu.whit  0.39862 -0.39324 -0.215994 -0.230512 -0.175736 -0.020574
## acn.poly  0.29575 -0.29428  0.156874  0.444956  0.061630 -0.126857
## amb.aure  0.17242 -0.05354 -0.041495  0.459242  0.072075  0.307651
## amb.cura -0.50387 -0.42986 -0.024245  0.011561  0.127535  0.012262
## amb.leuc  0.24375 -0.23786  0.136541  0.028162 -0.097926  0.373732
## amp.akin  0.08714  0.24320 -0.259432  0.352502 -0.110470  0.282233
## amp.clar -0.07053  0.49040 -0.282152 -0.076162 -0.170052 -0.106559
## amp.mela -0.01347  0.02095  0.515011 -0.073951 -0.271962  0.072117
## amp.peri  0.10372 -0.06009  0.176475  0.009064  0.273628 -0.125688
## chr.alis -0.32174 -0.13858 -0.158218  0.315366 -0.252461 -0.358979
## chr.lepi  0.12845  0.39671 -0.196386 -0.206075  0.178960 -0.244934
## chr.marg  0.14690  0.14568  0.076212 -0.045410  0.463959 -0.204090
## chr.tern -0.08762  0.15894 -0.162852  0.187699 -0.205306  0.396930
## chr.viri -0.31372 -0.17712 -0.220996  0.379202 -0.259790 -0.110179
## chr.webe  0.41034 -0.36908 -0.229689 -0.277514 -0.176346 -0.071793
## chr.xant  0.33785 -0.36208 -0.225573 -0.338710 -0.194370 -0.021957
## chy.cyan  0.33785 -0.36208 -0.225573 -0.338710 -0.194370 -0.021957
## chy.flav  0.17663 -0.03738 -0.048634  0.456347  0.078587  0.303659
## chy.rex   0.37729 -0.25346  0.158128  0.084928 -0.153207 -0.120968
## chy.roll -0.46780 -0.08951 -0.085420 -0.240278  0.193017  0.220226
## chy.talb  0.48315 -0.33436 -0.156873 -0.131655 -0.021849 -0.034676
## das.arua -0.14115  0.11983  0.468754 -0.088166 -0.286340  0.109579
## das.reti  0.26936  0.22029  0.025710  0.132111  0.294194 -0.016097
## das.trim  0.16418  0.21857 -0.081942 -0.037291  0.364127 -0.167839
## dis.mela -0.44746 -0.21703  0.380647 -0.195615  0.086775  0.073649
## dis.pers -0.33768 -0.01578  0.455202 -0.014191 -0.318797  0.057016
## dis.pros -0.61661 -0.24269  0.009592 -0.086497  0.096826  0.019691
## dis.pseu -0.32658 -0.15982  0.159176  0.183557 -0.317450 -0.246025
## hgy.plag -0.58366 -0.30691 -0.087950 -0.065793  0.151243  0.006203
## neg.mela -0.21683  0.21443 -0.394286  0.128747 -0.325971 -0.177912
## neg.nigr -0.07142 -0.48493  0.326830  0.127779  0.069717 -0.230511
## neo.azys -0.27253 -0.36310 -0.159683  0.391081  0.010686  0.083854
## neo.cyan -0.05513  0.37283 -0.150648 -0.154607 -0.098516 -0.161079
## pgy.dick  0.33785 -0.36208 -0.225573 -0.338710 -0.194370 -0.021957
## pgy.lacr  0.25495 -0.14912  0.542489 -0.072325 -0.117476 -0.010212
## pom.adel -0.51543 -0.03938 -0.186250  0.073550 -0.225056  0.102696
## pom.ambo -0.03098  0.42103  0.424132 -0.124514 -0.084066  0.002887
## pom.bank  0.25651 -0.17142  0.157411  0.231577  0.054708 -0.264610
## pom.brac  0.46792 -0.28082 -0.094161 -0.063335 -0.147129  0.360747
## pom.chry  0.04138  0.38423  0.228579 -0.104038 -0.229685 -0.165112
## pom.coel  0.31375  0.08344  0.058390  0.389115  0.239269 -0.023073
## pom.gram -0.51409 -0.33874 -0.051160 -0.128472  0.195373 -0.024673
## pom.lepi  0.46488 -0.32997 -0.005540 -0.127255 -0.086308 -0.193079
## pom.molu -0.47077 -0.27995 -0.160364 -0.113964  0.078918  0.181714
## pom.naga  0.05716  0.57896 -0.227224 -0.102932 -0.175195 -0.060764
## pom.pavo -0.01347  0.02095  0.515011 -0.073951 -0.271962  0.072117
## pom.phil  0.10372 -0.06009  0.176475  0.009064  0.273628 -0.125688
## pom.vaiu  0.20457 -0.14456  0.115550  0.202010  0.061314 -0.295638
## pom.ward -0.26503 -0.25922 -0.190424  0.278866 -0.270421 -0.359023
## pre.biac -0.49335  0.12984 -0.104803 -0.074152 -0.153793 -0.147121
## ste.apic  0.46126 -0.35932  0.062863  0.222298 -0.004796  0.030094
## ste.fasc -0.01405  0.12662  0.242576 -0.106959 -0.072540  0.031099
## ste.livi -0.09204 -0.01065 -0.065753 -0.074514  0.039723  0.367842
## ste.nigr -0.58723 -0.28640  0.081650 -0.039123  0.067851 -0.110306
## 
## 
## Site scores (weighted sums of species scores)
## 
##            PC1      PC2     PC3      PC4     PC5     PC6
## sit1  -0.93429  1.14681 -1.3318  0.48051 -1.3949  0.8130
## sit2  -2.84456 -1.76235  0.1020 -1.50702  2.1676  0.5541
## sit3  -0.09629  0.14975  3.6805 -0.52848 -1.9436  0.5154
## sit4   1.46195 -1.03306  0.8258  1.44365  0.4382 -2.1128
## sit5   0.68520  1.84393 -0.5211 -0.50571  2.5496 -1.0835
## sit6   2.41440 -2.58755 -1.6120 -2.42056 -1.3891 -0.1569
## sit7   1.23222 -0.38260 -0.2965  3.28194  0.5151  2.1986
## sit8  -0.65773 -0.07614 -0.4699 -0.53251  0.2839  2.6288
## sit9   0.51828  0.49694 -0.5933 -0.10762  0.2692  0.6831
## sit10 -2.54240 -1.35673 -0.8371  1.76191 -1.4142 -2.2513
## sit11  0.74122 -0.42939  1.2612  0.06478  1.9555 -0.8982
## sit12 -0.13795  2.79377 -1.0600 -0.95696 -0.8849 -1.2943
## sit13  0.26033  0.29175 -0.8810  0.29045 -0.6340  0.1817
## sit14 -0.10038  0.90488  1.7335 -0.76438 -0.5184  0.2222

2.3 Part III

  1. Extract the site scores, and use the bind_cols() function to merge your metdata with the site scores.
  2. Create convex hulls grouped by site exposure.
  3. Extract loadings from species scores.
  4. Plot your PCA results, using color and convex hulls to indicate the four exposure regimes. Include the species as loadings (it will be messy). Indicate the variation explained by the principal components axes.
# extract the site scores and merge with metadata
lizard.scores <- as.data.frame(lizard.pca$sites) %>%
  bind_cols(lizard.meta)
lizard.scores
##               PC1         PC2        PC3         PC4        PC5        PC6
## sit1  -0.93428885  1.14680849 -1.3318275  0.48050919 -1.3948564  0.8130396
## sit2  -2.84455673 -1.76235287  0.1019847 -1.50702164  2.1675739  0.5541368
## sit3  -0.09629497  0.14974825  3.6804891 -0.52848372 -1.9435562  0.5153788
## sit4   1.46194921 -1.03305693  0.8257666  1.44365153  0.4381775 -2.1127524
## sit5   0.68520238  1.84392761 -0.5211412 -0.50570661  2.5496164 -1.0835098
## sit6   2.41440360 -2.58755188 -1.6120391 -2.42056355 -1.3890501 -0.1569157
## sit7   1.23221836 -0.38259696 -0.2965427  3.28193653  0.5150804  2.1986084
## sit8  -0.65773262 -0.07614061 -0.4699026 -0.53251175  0.2838743  2.6287586
## sit9   0.51827546  0.49693889 -0.5932970 -0.10761588  0.2692489  0.6830832
## sit10 -2.54239937 -1.35672736 -0.8371333  1.76191338 -1.4142322 -2.2512591
## sit11  0.74122380 -0.42939491  1.2611655  0.06477657  1.9554600 -0.8982195
## sit12 -0.13795320  2.79377332 -1.0600425 -0.95695704 -0.8849320 -1.2942955
## sit13  0.26033095  0.29174976 -0.8810285  0.29044831 -0.6340032  0.1816979
## sit14 -0.10037801  0.90487520  1.7335485 -0.76437533 -0.5184014  0.2222486
##                  Site  Exposure
## sit1       Big Vickis Sheltered
## sit2      Blue Lagoon    Lagoon
## sit3       Bommie Bay   Oblique
## sit4          Coconut   Exposed
## sit5          Granite Sheltered
## sit6            LTMP1   Exposed
## sit7            LTMP3   Exposed
## sit8    Monkey's Butt    Lagoon
## sit9       North Reef Sheltered
## sit10  Palfrey Lagoon    Lagoon
## sit11    Pidgin Point   Exposed
## sit12          Resort Sheltered
## sit13   Steve's Gully   Oblique
## sit14 Washing Machine   Oblique
# create convex hulls grouped by site exposure based on site scores
lizard.hulls <- lizard.scores %>%
  group_by(Exposure) %>%
  slice(chull(PC1, PC2))
lizard.hulls
## # A tibble: 13 × 8
## # Groups:   Exposure [4]
##        PC1     PC2    PC3     PC4    PC5    PC6 Site            Exposure 
##      <dbl>   <dbl>  <dbl>   <dbl>  <dbl>  <dbl> <chr>           <chr>    
##  1  2.41   -2.59   -1.61  -2.42   -1.39  -0.157 LTMP1           Exposed  
##  2  0.741  -0.429   1.26   0.0648  1.96  -0.898 Pidgin Point    Exposed  
##  3  1.23   -0.383  -0.297  3.28    0.515  2.20  LTMP3           Exposed  
##  4 -2.84   -1.76    0.102 -1.51    2.17   0.554 Blue Lagoon     Lagoon   
##  5 -2.54   -1.36   -0.837  1.76   -1.41  -2.25  Palfrey Lagoon  Lagoon   
##  6 -0.658  -0.0761 -0.470 -0.533   0.284  2.63  Monkey's Butt   Lagoon   
##  7  0.260   0.292  -0.881  0.290  -0.634  0.182 Steve's Gully   Oblique  
##  8 -0.0963  0.150   3.68  -0.528  -1.94   0.515 Bommie Bay      Oblique  
##  9 -0.100   0.905   1.73  -0.764  -0.518  0.222 Washing Machine Oblique  
## 10  0.518   0.497  -0.593 -0.108   0.269  0.683 North Reef      Sheltered
## 11 -0.934   1.15   -1.33   0.481  -1.39   0.813 Big Vickis      Sheltered
## 12 -0.138   2.79   -1.06  -0.957  -0.885 -1.29  Resort          Sheltered
## 13  0.685   1.84   -0.521 -0.506   2.55  -1.08  Granite         Sheltered
# extract the loadings from species scores
lizard.loadings <- as.data.frame(lizard.pca$species) %>%
  mutate(species = rownames(.))
lizard.loadings
##                  PC1         PC2          PC3          PC4          PC5
## abu.sexs -0.28419327 -0.26752383 -0.059225088 -0.307390321  0.337479497
## abu.whit  0.39861947 -0.39324233 -0.215993975 -0.230511815 -0.175735748
## acn.poly  0.29574626 -0.29428240  0.156873657  0.444956221  0.061630243
## amb.aure  0.17242438 -0.05353681 -0.041495242  0.459241551  0.072075223
## amb.cura -0.50386600 -0.42985734 -0.024244512  0.011560848  0.127534660
## amb.leuc  0.24375159 -0.23785582  0.136541457  0.028161508 -0.097926340
## amp.akin  0.08713807  0.24320191 -0.259432036  0.352502086 -0.110470123
## amp.clar -0.07052897  0.49039979 -0.282152148 -0.076161959 -0.170052176
## amp.mela -0.01347456  0.02095428  0.515011036 -0.073950754 -0.271961920
## amp.peri  0.10371949 -0.06008525  0.176474954  0.009064189  0.273627621
## chr.alis -0.32173627 -0.13858143 -0.158217639  0.315366094 -0.252461012
## chr.lepi  0.12845052  0.39670838 -0.196386028 -0.206074790  0.178959675
## chr.marg  0.14690154  0.14567668  0.076211943 -0.045409501  0.463958587
## chr.tern -0.08761978  0.15893725 -0.162851723  0.187699259 -0.205306171
## chr.viri -0.31371521 -0.17711991 -0.220996121  0.379202299 -0.259789579
## chr.webe  0.41034064 -0.36907879 -0.229688964 -0.277514217 -0.176345653
## chr.xant  0.33784762 -0.36207627 -0.225572719 -0.338709585 -0.194369849
## chy.cyan  0.33784762 -0.36207627 -0.225572719 -0.338709585 -0.194369849
## chy.flav  0.17662542 -0.03737942 -0.048634293  0.456346780  0.078587053
## chy.rex   0.37728806 -0.25346430  0.158128024  0.084928439 -0.153207474
## chy.roll -0.46779936 -0.08951004 -0.085420015 -0.240278383  0.193017265
## chy.talb  0.48315353 -0.33436207 -0.156872787 -0.131655148 -0.021849360
## das.arua -0.14114944  0.11982924  0.468754200 -0.088166296 -0.286340297
## das.reti  0.26936274  0.22028882  0.025710178  0.132111229  0.294193936
## das.trim  0.16418492  0.21857114 -0.081941651 -0.037291421  0.364126691
## dis.mela -0.44746086 -0.21703150  0.380647325 -0.195614790  0.086774575
## dis.pers -0.33768073 -0.01578407  0.455202332 -0.014191389 -0.318797423
## dis.pros -0.61661247 -0.24269083  0.009591828 -0.086497132  0.096825901
## dis.pseu -0.32657673 -0.15982377  0.159175811  0.183557472 -0.317450009
## hgy.plag -0.58366260 -0.30690735 -0.087949915 -0.065792718  0.151242537
## neg.mela -0.21682695  0.21443247 -0.394286062  0.128746908 -0.325971020
## neg.nigr -0.07142109 -0.48492550  0.326829923  0.127779395  0.069716543
## neo.azys -0.27253308 -0.36310181 -0.159682667  0.391081209  0.010686048
## neo.cyan -0.05513116  0.37282574 -0.150647644 -0.154606936 -0.098516033
## pgy.dick  0.33784762 -0.36207627 -0.225572719 -0.338709585 -0.194369849
## pgy.lacr  0.25495205 -0.14912186  0.542488557 -0.072324509 -0.117475989
## pom.adel -0.51543119 -0.03938283 -0.186250081  0.073550387 -0.225056482
## pom.ambo -0.03098304  0.42102544  0.424131623 -0.124514067 -0.084065539
## pom.bank  0.25651170 -0.17142361  0.157410876  0.231577426  0.054707745
## pom.brac  0.46792295 -0.28082448 -0.094160546 -0.063335489 -0.147129336
## pom.chry  0.04137882  0.38423187  0.228579436 -0.104037870 -0.229684893
## pom.coel  0.31374852  0.08344050  0.058390166  0.389114846  0.239269183
## pom.gram -0.51408622 -0.33873889 -0.051160453 -0.128471569  0.195372569
## pom.lepi  0.46488159 -0.32997179 -0.005540028 -0.127255022 -0.086308343
## pom.molu -0.47076713 -0.27995181 -0.160363640 -0.113964393  0.078918117
## pom.naga  0.05715818  0.57895542 -0.227224109 -0.102931912 -0.175194614
## pom.pavo -0.01347456  0.02095428  0.515011036 -0.073950754 -0.271961920
## pom.phil  0.10371949 -0.06008525  0.176474954  0.009064189  0.273627621
## pom.vaiu  0.20457063 -0.14455571  0.115549561  0.202010234  0.061314200
## pom.ward -0.26503479 -0.25921597 -0.190424056  0.278866024 -0.270420530
## pre.biac -0.49334666  0.12984104 -0.104803086 -0.074152045 -0.153793321
## ste.apic  0.46125538 -0.35932241  0.062863410  0.222298460 -0.004795639
## ste.fasc -0.01404590  0.12661923  0.242575533 -0.106959081 -0.072539937
## ste.livi -0.09203656 -0.01065436 -0.065753489 -0.074514397  0.039722552
## ste.nigr -0.58723132 -0.28640372  0.081650061 -0.039123290  0.067850831
##                   PC6  species
## abu.sexs  0.033508875 abu.sexs
## abu.whit -0.020574399 abu.whit
## acn.poly -0.126856893 acn.poly
## amb.aure  0.307651394 amb.aure
## amb.cura  0.012262000 amb.cura
## amb.leuc  0.373731524 amb.leuc
## amp.akin  0.282233288 amp.akin
## amp.clar -0.106559193 amp.clar
## amp.mela  0.072116986 amp.mela
## amp.peri -0.125687908 amp.peri
## chr.alis -0.358978925 chr.alis
## chr.lepi -0.244934146 chr.lepi
## chr.marg -0.204089843 chr.marg
## chr.tern  0.396929932 chr.tern
## chr.viri -0.110179025 chr.viri
## chr.webe -0.071793253 chr.webe
## chr.xant -0.021957216 chr.xant
## chy.cyan -0.021957216 chy.cyan
## chy.flav  0.303658541 chy.flav
## chy.rex  -0.120968236  chy.rex
## chy.roll  0.220225547 chy.roll
## chy.talb -0.034675977 chy.talb
## das.arua  0.109579294 das.arua
## das.reti -0.016097258 das.reti
## das.trim -0.167839287 das.trim
## dis.mela  0.073649307 dis.mela
## dis.pers  0.057016283 dis.pers
## dis.pros  0.019690868 dis.pros
## dis.pseu -0.246024920 dis.pseu
## hgy.plag  0.006202785 hgy.plag
## neg.mela -0.177911878 neg.mela
## neg.nigr -0.230511305 neg.nigr
## neo.azys  0.083854305 neo.azys
## neo.cyan -0.161078552 neo.cyan
## pgy.dick -0.021957216 pgy.dick
## pgy.lacr -0.010211576 pgy.lacr
## pom.adel  0.102696006 pom.adel
## pom.ambo  0.002886777 pom.ambo
## pom.bank -0.264610435 pom.bank
## pom.brac  0.360747040 pom.brac
## pom.chry -0.165111671 pom.chry
## pom.coel -0.023073342 pom.coel
## pom.gram -0.024672657 pom.gram
## pom.lepi -0.193078642 pom.lepi
## pom.molu  0.181714380 pom.molu
## pom.naga -0.060763511 pom.naga
## pom.pavo  0.072116986 pom.pavo
## pom.phil -0.125687908 pom.phil
## pom.vaiu -0.295637553 pom.vaiu
## pom.ward -0.359022962 pom.ward
## pre.biac -0.147120789 pre.biac
## ste.apic  0.030093941 ste.apic
## ste.fasc  0.031099259 ste.fasc
## ste.livi  0.367842329 ste.livi
## ste.nigr -0.110305800 ste.nigr
# plot PCA results with color and convex hulls as exposure and species as loadings
lizard.plot <- ggplot() +
  geom_point(data = lizard.scores, aes(x = PC1, y = PC2, color = Exposure), size = 2) +
  geom_polygon(data = lizard.hulls, aes(x = PC1, y = PC2, fill = Exposure), alpha = 0.5) +
  geom_segment(data = lizard.loadings, aes(x = 0, xend = PC1*3,
                                           y = 0, yend = PC2*3), lwd = 0.1) +
  geom_text(data = lizard.loadings, aes(x = PC1*3, y = PC2*3, label = species), size = 3) +
  scale_fill_fish_d(option = "Stegastes_nigricans", end = 0.8) +
  scale_color_fish_d(option = "Stegastes_nigricans", end = 0.8) +
  theme_bw() +
  xlab("PC1 (21.8%)") +
  ylab("PC2 (15.5%)")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
lizard.plot