How to convert landmark data from csv file into array to procrustes superimposition using geomorph package?

28 views Asked by At

I have three separate csv files with landmark coordinates for separate species. I would like to perform a procrustes superimposition on the landmarks, but I first need to combine the landmarks into one object which I am trying to do with the combine.subsets function. However, for this function to work, my data must be formatted as an array.

I tried using the function arrayspecs to format my data, but got an error message "Error in dimnames(specimens) <- *vtmp* : length of 'dimnames' [3] not equal to array extent"

I then successfully used the array function, however, when I tried to use the combine.subsets function, I got the error message "Error in combine.subsets(a.tex, c.ero, c.cal, gpa = TRUE, CS.sets = NULL, :

Coordinates must be a [p x k x n] array.

                                       Use arrayspecs first" 

This is my data and the code I've been working with: A_ardys

x.1 X Y
1 7.897 10.414
2 8.641 10.543
3 9.353 10.635
4 9.560 10.141
5 9.560 9.601
6 8.560 9.761

C_erodyle

x.1 X Y
1 7.545 9.116
2 8.608 9.201
3 9.651 9.245
4 10.091 8.224
5 9.915 7.257
6 8.641 7.927

C_californica

x.1 X Y
1 7.545 9.116
2 8.608 9.201
3 9.651 9.245
4 10.091 8.224
5 9.915 7.257
6 8.641 7.927

Code:

texana <- read.csv("A_texana.csv", row.names = 1) 
erodyle <- read.csv("C_erodyle.csv", row.names = 1) 
californica <- read.csv("C_californica.csv", row.names = 1)

windows()
plot(texana$X,texana$Y, col = "red", xlim = c(4,10), ylim = c(0,12)) 
points(erodyle$X,erodyle$Y, col = "blue") 
points(californicus$X,californicus$Y, col = "green")

library(geomorph)
library(reshape2) 
library(ggfortify) 
library(ggplot2) 
library(dplyr) 

################################
#  procrustes superimposition  # 
################################

# Combine landmarks
?two.d.array 
?arrayspecs 
?array
#arrayspecs attempt 
a.tex <- arrayspecs(texana, 6, 2) 
c.ero <- arrayspecs(erodyle, 6, 2)
c.cal <- arrayspecs(californica, 6, 2)
# Create an array with dimensions (matrix, landmarks, ndimensions)
a.t <- array(data = texana, dim = length(texana), dimnames = NULL) 
c.e <- array(data = erodyle, dim = length(erodyle), dimnames = NULL)
c.c <- array(data = californica, dim = length(californica), dimnames = NULL) 

landmarks <- combine.subsets(
  a.tex, c.ero, c.cal,
  gpa = TRUE,
  CS.sets = NULL,
  norm.CS = FALSE,
  weights = NULL
)

# Perform Procrustes superimposition
proc <- gpagen(landmarks, PrinAxes = FALSE, scaling = FALSE)
0

There are 0 answers