library(data.table) library(FactoMineR) library(factoextra) table = as.data.frame(fread( “https://esapubs.org/archive/ecol/E096/102/HeteropteraMorphometricTraitsRAW.txt”)) table.pca = PCA(table[,12:ncol(table)], graph = FALSE) fviz_pca_ind(table.pca, geom.ind = “point”, col.ind = table[,9], palette = c(“#00AFBB”, “#E7B800”, “#FC4E07”), addEllipses = TRUE, legend.title = “Geogr.loc.”)

library(dendextend) clusters = as.dendrogram(hclust(dist(table[,12:ncol(table)]), method = ‘average’)) clusters = set(clusters, “labels_cex”, 0.5)

family_colors = gsub(“Tingidae”,“red”,table\(Family) family_colors = gsub("Miridae","blue",family_colors) family_colors = gsub("Pentatomidae","green",family_colors) family_colors = gsub("Alydidae","yellow",family_colors) family_colors = gsub("Anthocoridae","orange",family_colors) family_colors = gsub("Coreidae","pink",family_colors) family_colors = gsub("Berytidae","violet",family_colors) family_colors = gsub("Rhopalidae","lightblue",family_colors) family_colors = gsub("Saldidae","darkred",family_colors) family_colors = gsub("Lygaeidae","darkblue",family_colors) family_colors = gsub("Plataspididae","darkgreen",family_colors) family_colors = gsub("Acanthosomatidae","darkorange",family_colors) family_colors = gsub("Scutelleridae","darkviolet",family_colors) family_colors = gsub("Nabidae","cyan",family_colors) family_colors = gsub("Reduviidae","darkcyan",family_colors) family_colors = gsub("Piesmatidae","coral",family_colors) colLab <- function(n) { if(is.leaf(n)) { a <- attributes(n) attr(n, "label") <- table\)Family[a\(label] attr(n, "nodePar") <- c(a\)nodePar, lab.col = family_colors[a$label]) } n } plot(dendrapply(clusters, colLab))

fviz_pca_ind(table.pca, geom.ind = “point”, col.ind = table$Family, palette = names(table(family_colors)), addEllipses = TRUE, legend.title = “Families”)