When performing GM analyses with geomorph it is necessary that all landmark coordinates be aligned via Generalized Procrustes Analysis using the gpagen function. Of important note, however, is that the gpagen function does not automatically reflect specimens that are of a different side than the rest of a bilateral dataset (i.e. left vs. right).

Avoiding mismatched sides altogether is often not feasible due to the nature of data collection, however there is a quick way to reflect off-sided landmarks using the rotate.coords function, which we will discuss here.

rotate.coords() (Expand for more details)`
  • \(A\): An array of two-dimensional landmark coordinates, a gpagen object, or a matrix of two-dimensional coordinates for a single specimen.
  • \(type\): Type of rotation for flip to be performed. Specimens can be flipped along the x-axis (“flipX”), and the y-axis (“flipY”), or rotated clockwise (“rotateC”) and counter-clockwise (“rotateCC”).
  • \(index\): To be used if only specific specimens within a dataset are to be rotated/flipped. If NULL (the default) all specimens are rotated. To specify specimens, a vector with a binary index (0 = do not rotate, 1 = rotate) the same length as the number of specimens is used.



Important Note

This function is meant to be used only for 2D landmark coordinates.



Manipulating a Whole Dataset

The original landmarks:
wings <- gpagen(mosquito$wingshape[,,1:5], print.progress = F)

plotAllSpecimens(wings$coords)



And the landmarks flipped along the x-axis:
wingsflip <- rotate.coords(wings$coords, type = "flipX")
plotAllSpecimens(wingsflip)



Manipulating Single Specimens

In this example, the fourth specimen is flipped along the x-axis opposite to the rest.

To re-align it to the rest of our data, we need to create a vector of binary inputs, the fourth of which is a 1. This specifies that the fourth specimen is the only one to be flipped. Then we run the function as normal:

flip <- c(0,0,0,1,0)

wingsflip <- rotate.coords(wings, type = "flipX", index = flip)

plotAllSpecimens(wingsflip)