# Importation coordinates, procrustes, etc.
library(geomorph)
library(Morpho)
# Plots
library(ggplot2)
library(ggfortify)
library(ggthemes)
library(ggrepel)
library(ggpubr)
library(viridis)
setwd("C:/Users/narim/EDDy Lab Dropbox/Narimane Chatar/DECAF data/Ontogeny Smilodon/R_data")
# "Data" contains measurements
# "Data" contains measurements
data <- read.csv("Smilodon_DATA.csv", sep=";", dec = ',', header = TRUE)
# Define semi landmarks
semilandmarks <- read.csv("Sliding_Smilodon_test.csv", sep = ";")
# Definition of the colors and shapes that will be used for each subfamily in all the analyses
shape_to_plot <- c("Adult_Smilo" = 15,
"Juv_Smilo"   = 16)
# Import all pts files using custom function from: https://github.com/cha-nar/importpts
source("importpts.R")
setwd("C:/Users/narim/EDDy Lab Dropbox/Narimane Chatar/DECAF data/Ontogeny Smilodon/R_data/Coordinates_Smilodon/test")
import.pts(30)
# Perform the superimposition
procrust <- gpagen(ptsarray, curves = semilandmarks)
# Visualize landmarks
spheres3d(procrust$coords[,,10],
radius=0.01,color="#FF0D68")
# # # PCA # # #
PCA <- gm.prcomp(procrust$coords)
eigenvalues <- PCA$d
scores <- PCA$x
df_pca <-cbind(as.data.frame(scores[,1:2]),data)
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category, label = SpecimenID)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot) +
geom_text_repel(size=3)
PCA_Smilo_only
setwd("C:/Users/narim/EDDy Lab Dropbox/Narimane Chatar/DECAF data/Ontogeny Smilodon/R_data")
# "Data" contains measurements
data <- read.csv("Smilodon_DATA.csv", sep=";", dec = ',', header = TRUE)
# Define semi landmarks
semilandmarks <- read.csv("Sliding_Smilodon_test.csv", sep = ";")
# Definition of the colors and shapes that will be used for each subfamily in all the analyses
shape_to_plot <- c("Adult_Smilo" = 15,
"Juv_Smilo"   = 16)
# Import all pts files using custom function from: https://github.com/cha-nar/importpts
source("importpts.R")
setwd("C:/Users/narim/EDDy Lab Dropbox/Narimane Chatar/DECAF data/Ontogeny Smilodon/R_data/Coordinates_Smilodon/test")
import.pts(30)
# Perform the superimposition
procrust <- gpagen(ptsarray, curves = semilandmarks)
# Visualize landmarks
# spheres3d(procrust$coords[,,10], radius=0.01,color="#FF0D68")
# # # PCA # # #
PCA <- gm.prcomp(procrust$coords)
eigenvalues <- PCA$d
scores <- PCA$x
df_pca <-cbind(as.data.frame(scores[,1:2]),data)
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category, label = SpecimenID)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot) +
geom_text_repel(size=3)
PCA_Smilo_only
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category, label = SpecimenID)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot) +
# geom_text_repel(size=3)
PCA_Smilo_only
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot) +
# geom_text_repel(size=3)
PCA_Smilo_only
PC1 <- PCA$x[,1]
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot) +
# geom_text_repel(size=3)
PCA_Smilo_only
PC1 <- PCA$x[,1]
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
# geom_text_repel(size=3)
PCA_Smilo_only
df_pca <-cbind(as.data.frame(scores[,1:2]),data, label = SpecimenID)
PCA_Smilo_only <- ggplot(data = df_pca,
aes(x = Comp1, y = Comp2, shape = Category, label = SpecimenID)) +
theme_minimal() +
geom_point(aes(shape = Category,
size = log10(MandibleL),
color = log10(MandibleL))) +
scale_color_viridis_c(option = "inferno") +
scale_size_continuous() +
labs(x = paste0('PC1 = ', round(((eigenvalues[1]/sum(eigenvalues))*100), digits = 2), '%'),
y = paste0('PC2 = ', round(((eigenvalues[2]/sum(eigenvalues))*100), digits = 2), '%')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot) +
geom_text_repel(size=3)
PCA_Smilo_only
plot_list = list()
vector_measurments <- c("Cheek teeth length", "Coronoid height", "Dentary height", "Diastema length", "Symphysis angle")
for (i in 1:vector_measurments)
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Family)) +
theme_minimal() +
geom_point(aes(shape = Family, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0(data[,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3,
labels = vector_measurments)
data
for (i in 1:vector_measurments)
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Family, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0(data[,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
for (i in 1:vector_measurments)
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0(data[,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
plot_list = list()
vector_measurments <- c("Cheek teeth length", "Coronoid height", "Dentary height", "Diastema length", "Symphysis angle")
for (i in 1:vector_measurments)
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0(data[,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
vector_measurments
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0(data[,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3,
labels = vector_measurments)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', data[,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3,
labels = vector_measurments)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', data[1,i+2])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3,
labels = vector_measurments)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', vector_measurments[1])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3,
labels = vector_measurments)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none") +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3,
labels = vector_measurments)
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 5)) +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 10)) +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 8)) +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 10)) +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio ', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 10)) +
scale_shape_manual(values = shape_to_plot)
})
}
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
vector_measurments <- c("Cheek teeth length", "Coronoid height", "Dentary height", "Diastema length")
for (i in 1:length(vector_measurments))
{
plot_list[[i]] <-  local ({
i <- i
p <- ggplot(data = data, aes(x = log10(MandibleL), y = (data[,i+2]/MandibleL), shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Ratio ', vector_measurments[i])) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 10)) +
scale_shape_manual(values = shape_to_plot)
})
}
plot_list[[5]] <-  local ({
p <- ggplot(data = data, aes(x = log10(MandibleL), y = SymphysisAngle, shape = Category)) +
theme_minimal() +
geom_point(aes(shape = Category, color =  log10(MandibleL), size = log10(MandibleL)), alpha=0.8) +
scale_color_viridis(option = "inferno") +
labs(x = paste0('log10(Mandible length)'),
y = paste0('Symphysis Angle')) +
theme(axis.line = element_line(color = "darkgrey", size = 0.5),legend.position = "none", axis.title = element_text(size = 10)) +
scale_shape_manual(values = shape_to_plot) })
ggarrange(plotlist = plot_list, ncol = 2, nrow = 3)
