Morphospace Plots

Morphometrics Lesson 6

Author

Ryan N. Felice

#remotes::install_github("millacarmona/morphospace")
library(morphospace)
library(geomorph)
library(phytools)
library(Morpho)
library(tidyverse)
library(Rvcg)
library(rgl)
library(scatterplot3d)

What is a morphospace and what is it good for?

Lets practice making nice morphospace plots using some landmark data. Morphospace plots are just a fancy way of saying “ordination plot.” With GMM data, we are typically talking about plotting principal component analyses (PCA).

Here is an example:

Felice, R. N., D. Pol, and A. Goswami. 2021. Complex macroevolutionary dynamics underly the evolution of the crocodyliform skull. Proceedings of the Royal Society B: Biological Sciences 288:20210919.

There is a lot of data packed into this plot! The most important this is seeing which data points (in this case, species, but it could be individuals) are similar and different from one another. The colors and shapes tell us about the phylogenetic affinities and whether the species is extinct. The images on the x and y axes show us which aspects of shape are most variable and how shape variation partitions specimens.

Lets try to recreate something like this!

#import data:
raw_data<-read.csv('./Data/crocs.csv',row.names = 1)
shape_data <- arrayspecs(raw_data, p=ncol(raw_data)/3, k=3)
#remove one specimen that has no ecology data:
bad_specimen <- which(dimnames(shape_data)[[3]]== "Crocodylus_biporcatus")
shape_data <- shape_data[,,-bad_specimen]
#phylogeny:
phylo1 <- read.nexus('./Data/CrocTree2.nex')
#ecological data
eco_dat <- read_csv('./Data/croc_ecology_data.csv')
#make sure tips and data are in same order
shape_data <- shape_data[,,eco_dat$Tip_label]

Now do a Procrustes superimposition…

gpa <- gpagen(shape_data)

…and carry out a principal components analysis of the aligned landmark coordinates.

PCA <- gm.prcomp(gpa$coords)
#look at the morphospace
plot(PCA)

Pretty boring, right? and there really isn’t much we can learn from this on its own.

Some of the things we might want to explore/visualize in a morphospace:

  • how is shape variation distributed?

  • do species with similar ecology cluster together?

  • do species with similar body size have similar skull shapes?

The morphospace package makes it very easy to do these sorts of data explorations

#define some good color-blind friendly colors:
#see https://davidmathlogic.com/colorblind/#%23D81B60-%231E88E5-%23FFC107-%23004D40
cbb_colors<-c("#D81B60","#1E88E5","#FFC107","#004D40","black")
habitats<-as.factor(eco_dat$Habitat)
names(habitats)<-eco_dat$Tip_label
fossils<-as.factor(eco_dat$extinct)
names(fossils)<-eco_dat$Tip_label
habitat_colors<-cbb_colors[habitats]
mspace(gpa$coords) 
Preparing for snapshot: rotate mean shape to the desired orientation
 (don't close or minimize the rgl device).Press <Enter> in the console to continue:

This can take a few seconds...
DONE.

msp<-mspace(gpa$coords, plot=FALSE) %>%
  # scatter points
  proj_shapes(shapes = gpa$coords, col = habitat_colors) %>% 
  # convex hulls enclosing groups
  proj_groups( groups = habitats, col=cbb_colors[1:3], alpha = 0.5) %>%
    plot_mspace(legend = TRUE, cex.legend = .7)

I Still think those clusters of landmarks are hard to interpret- lets use warps of a mesh of a specimen

NOTE: there is a good chance this wont work at all on Mac

#load in a mesh
m1<-vcgImport("./Data/Alligator_mississippiensis.ply")
shade3d(m1, col="#E4D1C0", specular="black")
#make a "hypothetical shape",
#the mean of all specimens,
#by warping the skull of the alligator to the landmark configuration of the mean specimen
mean_skull <- warpRefMesh(mesh=m1,
                          mesh.coord = shape_data[,,"Alligator_mississippiensis"],
                          gpa$consensus)

and now plot with 3D models representing shape change:

mspace(gpa$coords, template= mean_skull,bg.model = "gray",
                  cex.ldm = 0, adj_frame = c(0.9, 0.85)) %>%
  # scatter points
  proj_shapes(shapes = gpa$coords, col = habitat_colors) 
Preparing for snapshot: rotate mean shape to the desired orientation
 (don't close or minimize the rgl device).Press <Enter> in the console to continue:

This can take a few seconds...
DONE.

Phylomorphospace

Another useful way of using morphospace is to project the phylogenetic tree into the ordination so that we can make hypotheses about how evolutionary relationships relate to phenotypic similarities or differences. For example, this will help us see if there could be convergent evolution if we see two species with very similar shapes (positions in morphospace) that have ancestors in completely different parts of morphospace.

eco_dat_phylo<-eco_dat[match(phylo1$tip.label, eco_dat$Tip_label),]
habitats_phylo<-as.factor(eco_dat_phylo$Habitat)
names(habitats_phylo)<-eco_dat_phylo$Tip_label
tip_colors<-cbb_colors[habitats_phylo]

msp<-mspace(gpa$coords, models=FALSE) %>%
  # scatter points
  proj_shapes(shapes = gpa$coords, col = habitat_colors) %>% 
  # phylogenetic relationships
  proj_phylogeny(shapes = gpa$coords, tree = phylo1, col.tips=tip_colors)
Preparing for snapshot: rotate mean shape to the desired orientation
 (don't close or minimize the rgl device).Press <Enter> in the console to continue:

This can take a few seconds...
DONE.

EXERCISE: What patterns do you notice in the data? hint: think convergent evolution

EXERCISE: See if you can add tip labels to the plot so you can see which taxa are (potentially) converging!

Other Ways of Plotting Morphospace

Let’s try a different type of morphospace plot that is particularly relevant to us as paleontologists.

From: Foote, M. 1994. Morphological disparity in Ordovician-Devonian crinoids and the early saturation of morphological space. Paleobiology 20:320–344.

As paleontologists, we might be interested in how morphological variation expands and contracts through time.

First, lets prep by:

  1. calculating the % variance explained by each PC axis so we can add that to the axis labels

  2. We need a way to tell R how far apart to place the grids that represent time periods. We have a vector, eco_dat$time, that lists the time bin in which each species lived. We need to change these to equally spaced numerical bins that will become the z-axis values for the plot.

PCA_summary<-invisible(summary(PCA))

time_period<-as.factor(eco_dat$time)
levels(time_period)<-c(40,20,0,60)
time_period2<-as.numeric(as.character(time_period))

Now we can build the plot

#stacked morphospace

plot3d1<-scatterplot3d(x = PCA$x[,1], #PC axis 1 scores
                       y = PCA$x[,2], #PC axis 2 scores
                       z = time_period2, #time bins
                       pch =19, #shape of the points
                       angle = 10,
                       color=habitat_colors, #color the points
                       z.ticklabs=c("Jurassic",
                                    "",
                                    "Cretaceous",
                                    "",
                                    "Cenozoic",
                                    "",
                                    "Modern"),
                       xlab=paste0("PC Axis 1 (",
                                   signif(PCA_summary$PC.summary[2,1],3)*100,
                                   "% of total variance)"),
                       ylab=paste0("PC Axis 2 (",
                                   signif(PCA_summary$PC.summary[2,2],3)*100,
                                   "% of total variance)"),
                       label.tick.marks = TRUE,
                       zlab="Geologic Time Period",
                       #additional graphics options for a clean plot
                       box=F,x.ticklabs=NA,y.ticklabs=NA) 
plot3d1$plane3d(20,0,0,lty="solid",col="grey")
plot3d1$plane3d(40,0,0,lty="solid",col="grey")
plot3d1$plane3d(60,0,0,lty="solid",col="grey")
plot3d1$points3d(x = PCA$x[,1], 
                       y = PCA$x[,2], 
                       z = time_period2, 
                       pch =19, 
                       col=habitat_colors)

looks pretty good!

Exercises

  • Try experimenting with the “angle” argument in scatterplot3d to see how you can change the appearance of the plot.

  • What does this tell us about morphospace occupation through time and changes in morphological disparity through time?

  • What are some issues with this dataset that this plot reveals?