# Load the morphological measures (imputed)
imputed_data <- read.csv("Supplementary_table_Sx_Morpho_traits_imputed.csv")
species <- unique(imputed_data$species) # list of species
species
[1] Abi Aca Aco Alo Amu Ase Ash Asp Ata Aum Aun Tmo Tur Tca Hsp Str
Levels: Abi Aca Aco Alo Amu Ase Ash Asp Ata Aum Aun Hsp Str Tca Tmo Tur
# List of variables included in the table
colnames(imputed_data)[-(1:3)]
[1] "spike_length_mm" "spikelet_nb" "tot3_fertile" "tot_nb_fertile_fls"
[5] "spikelet_length_mm" "flower_length_mm" "eta_len1" "eta_len2"
[9] "eta_len3" "eta_len4" "eta_len5" "eta_len6"
[13] "eta_wid1" "eta_wid2" "eta_wid3" "eta_wid4"
[17] "eta_wid5" "eta_wid6" "ova1" "ova2"
[21] "ova3" "sti1" "sti2" "sti3"
[25] "n_AF_splets" "tot_AF_fertile" "mean_eta_len" "mean_eta_wid"
[29] "eta_len_norm" "eta_wid_norm" "sti_mean" "ova_mean"
[33] "sti_norm" "maleinvest" "compactness" "AF_index"
We will use 6 variables describing traits that we suppose to be most
affected by species mating system:
# Subset variables
attach(imputed_data)
var <- as.data.frame(cbind(eta_len_norm,eta_wid_norm,sti_norm,compactness,AF_index,maleinvest))
detach(imputed_data)
We want to use a palette that aims to have at its extremes bluish colors (meant for outcrossing species Ae. speltoides and Ae. mutica) and reddish colors (meant for selfing ones Ae. tauschii, T. urartu). In the middle yellow/green colors for the other self-compatible species.
library("pals")
jet
pal.bands(kovesi.diverging_rainbow_bgymr_45_85_c67(13))
library("ade4") # for PCA
pca_individuals <- dudi.pca(var, scale=T, scannf = F, nf = 4) # n axes = 2
inertie <- pca_individuals$eig/sum(pca_individuals$eig)*100
#save.image("/home/concetta/TRABAJO/TRANS/manip_serre_Triticeae/morpho_PCA_imputed.Rdata")
# Create vector of colors matching the order of individuals in the trait table
mycol <- rep(NA, nrow(imputed_data))
mycol[which(imputed_data$species_code == "Amu")] <- "#085CF8"
mycol[which(imputed_data$species_code == "Asp")] <- "#1684A6" # "royalblue"
mycol[which(imputed_data$species_code == "Ash")] <- "#3C9E49"
mycol[which(imputed_data$species_code == "Aca")] <- "#65AF1E"
mycol[which(imputed_data$species_code == "Alo")] <- "#98BB18"
mycol[which(imputed_data$species_code == "Aum")] <- "#C7C612"
mycol[which(imputed_data$species_code == "Abi")] <- "#F3CC1D"
mycol[which(imputed_data$species_code == "Aco")] <- "#FDAF55"
mycol[which(imputed_data$species_code == "Tmo")] <- "#FE8F7B"
mycol[which(imputed_data$species_code == "Ase")] <- "#FC6A9B"
mycol[which(imputed_data$species_code == "Aun")] <- "#F64497"
mycol[which(imputed_data$species_code == "Ata")] <- "#E92952"
mycol[which(imputed_data$species_code == "Tur")] <- "#D70500"
mycol[which(imputed_data$species_code == "Hsp")] <- "coral4"
mycol[which(imputed_data$species_code == "Tca")] <- "brown4"
mycol[which(imputed_data$species_code == "Sst")] <- "navy"
op <- par(mfrow=c(1,2), cex=0.8)
# 1. plot space of variables
s.corcircle(pca_individuals$co, clabel=1.5)
# 2. scatterplot PC1-PC2
x = pca_individuals$li[,1]
y = pca_individuals$li[,2]
plot(x, y, col=mycol, cex=0.6, pch=19, #pch=patterns,
xlab=paste("PC1 (",round(inertie[1]),"%)",sep=""), ylab=paste("PC2 (",round(inertie[2]),"%)",sep=""))
# Add species name in the centroid position
centroid_x <- tapply(x, imputed_data$species_code,mean) # species are in alphabetical order
centroid_y <- tapply(y, imputed_data$species_code,mean)
points(centroid_x, centroid_y, pch=18, col=mycol[match(sort(species),imputed_data$species_code)] , cex=1.6)
# tune the y position
centroid_y_text <- centroid_y + 0.25
centroid_x_text <- centroid_x - 0.2
centroid_x_text[c(11:13)] <- centroid_x[c(11:13)] + 0.2
centroid_y_text[c(6,14:16)] <- centroid_y[c(6,14:16)] - 0.2
text(centroid_x,centroid_y_text,labels=sort(species),
col=mycol[match(sort(species),imputed_data$species_code)], cex=1, font=2)
par(op)
[1] Abi Aca Aco Alo Amu Ase Ash Asp Ata Aum Aun Tbo Tur Tca Hsp Str
Levels: Abi Aca Aco Alo Amu Ase Ash Asp Ata Aum Aun Hsp Str Tbo Tca Tur