GPA
DMA
6/12/2021
Supplementary material- GPA
Here we describe the Generalized Procrustes Analyses for the models of the ammonoid whorl shapes. This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. For more details on using R Markdown see http://rmarkdown.rstudio.com
Setting the working directory and loading the dataset:
# Clean previous loaded data
rm(list=ls())
# Setting the workind directory:
setwd("F:/Documentos/1.1.Proyectos/16. Patterns of variation in the ammonoid cross section/Data")
#Loading the dataset :
library(geomorph)
## Loading required package: RRPP
## Loading required package: rgl
## Loading required package: Matrix
tps<-readland.tps("amm_corrected.tps", specID = c("ID"))
##
## No curves detected; all points appear to be fixed landmarks.
##
## Warning: not all specimens have scale adjustment (perhaps because they are already scaled);
## no rescaling will be performed in these cases
##
## Negative landmark coordinates have been identified and imported as such.
## If you want to treat them as NAs please set negNA = TRUE
#checking the object
class(tps)
## [1] "array"
Checking the landmark configurations:
library(randomcoloR)
plot(tps [,,1],
col = randomColor(count = 1),
pch = 19,
xlim=c(-2,2),
ylim=c(-40,40),
asp = 1
)
points(tps[,, 2], col = randomColor(count = 1), pch = 19)
points(tps[,, 3], col = randomColor(count = 1), pch = 19)
points(tps[,, 4], col = randomColor(count = 1), pch = 19)
points(tps[,, 5], col = randomColor(count = 1), pch = 19)
points(tps[,, 6], col = randomColor(count = 1), pch = 19)
points(tps[,, 7], col = randomColor(count = 1), pch = 19)
Performing the GPA
library(Morpho)
##
## Attaching package: 'Morpho'
## The following object is masked from 'package:RRPP':
##
## classify
gpa <- procSym(dataarray = tps ) #the conformation were already aligned, further alignment is not required.
## performing Procrustes Fit
## in... 0.8076971 secs
## Operation completed in 0.854990005493164 secs
centroid_size <- gpa$size #centroid size
consenso <- rotate.coords(gpa$mshape, type = "rotateCC") # mean shape or concensus
confs<- rotate.coords(gpa$orpdata, type = "rotateCC")
#final array with the transformed conformations
plotting the mean shape
consenso
## [,1] [,2]
## [1,] -1.325726e-16 0.42042743
## [2,] 1.962269e-01 0.32060704
## [3,] 2.533080e-01 0.01190271
## [4,] 2.229165e-01 -0.12610023
## [5,] 1.318695e-01 -0.17285208
## [6,] 1.341505e-01 0.01190934
## [7,] 1.292372e-01 -0.01992816
## [8,] 1.270626e-01 -0.17160228
## [9,] 9.589887e-02 -0.05416152
## [10,] -3.640260e-17 -0.01997707
## [11,] -1.962269e-01 0.32060704
## [12,] -2.533080e-01 0.01190271
## [13,] -2.229165e-01 -0.12610023
## [14,] -1.318695e-01 -0.17285208
## [15,] -1.341505e-01 0.01190934
## [16,] -1.292372e-01 -0.01992816
## [17,] -1.270626e-01 -0.17160228
## [18,] -9.589887e-02 -0.05416152
plot(consenso)
text(consenso, labels = 1:nrow(consenso), asp = 1)
links <- list(c(1:10),c(11:18),c(11,1), c(18,10))
lineplot(consenso, links)
GPA results
gpa$Variance
## eigenvalues % Variance Cumulative %
## 1 6.035052e-02 5.456634e+01 54.56634
## 2 2.751180e-02 2.487498e+01 79.44132
## 3 8.267819e-03 7.475406e+00 86.91673
## 4 5.736866e-03 5.187027e+00 92.10376
## 5 3.536971e-03 3.197977e+00 95.30173
## 6 1.867274e-03 1.688309e+00 96.99004
## 7 1.092251e-03 9.875662e-01 97.97761
## 8 9.321029e-04 8.427673e-01 98.82038
## 9 4.428273e-04 4.003854e-01 99.22076
## 10 2.943113e-04 2.661036e-01 99.48687
## 11 2.161133e-04 1.954004e-01 99.68227
## 12 1.754544e-04 1.586383e-01 99.84090
## 13 1.072126e-04 9.693704e-02 99.93784
## 14 6.277965e-05 5.676266e-02 99.99460
## 15 5.830823e-06 5.271979e-03 99.99988
## 16 1.364563e-07 1.233779e-04 100.00000
Exporting the results
write.csv(gpa$Variance, "F:/Documentos/1.1.Proyectos/16. Patterns of variation in the ammonoid cross section/Data/GPAvariance.csv", row.names = FALSE)
write.csv(gpa$PCscores, "F:/Documentos/1.1.Proyectos/16. Patterns of variation in the ammonoid cross section/Data/PCscores.csv", row.names = FALSE)
write.csv(centroid_size, "F:/Documentos/1.1.Proyectos/16. Patterns of variation in the ammonoid cross section/Data/cds.csv", row.names = FALSE)
Plotting PCscores
PC1 vs PC2
library(ggplot2)
df<-read.csv2("F:/Documentos/1.1.Proyectos/16. Patterns of variation in the ammonoid cross section/Data/SuppData1.csv", dec =".")
ggplot(df,
aes(-PC1, PC2,group =ST, color = ST))+ geom_point() +
labs(x="PC1", y="PC2")+ geom_text(aes(label=O),hjust=0, vjust=0, size=0)
PC1 vs PC3
ggplot(df,
aes(-PC1, PC3))+ geom_point() +
labs(x="PC1", y="PC3")
3D plot
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:Morpho':
##
## export
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
plot_ly(df, x = ~-PC1, y = ~PC2, z = ~PC3, type="scatter3d", mode="markers", size = 1.5)
Predicting theoretical whorl shapes
library(morphospace)
links1 <- list(c(1:10),c(11:18),c(11,1), c(18,10))
mspace(confs,axes = c(1, 2), links = links1, cex.ldm = 1,nv=10, nh=12, points = FALSE,size.models = 2)
mspace(confs,axes = c(1, 3), links = links1, cex.ldm = 1,nv=10, nh=12, points = FALSE,size.models = 2 )
mspace(confs,axes = c(2, 3), links = links1, cex.ldm = 1,nv=10, nh=12, points = FALSE,size.models = 2)
mspace(confs,axes = c(1, 2), links = links1, cex.ldm = 1,nv=10, nh=12, size.models = 2, col.models = "red", points = TRUE)
mspace(confs,axes = c(1, 3), links = links1, cex.ldm = 1,nv=10, nh=12, size.models = 2,col.models = "red", points = TRUE )
mspace(confs,axes = c(2, 3), links = links1, cex.ldm = 1,nv=10, nh=12, size.models = 2,col.models = "red", points = TRUE)