Landmark orientation and adding grouping information

1,100 views
Skip to first unread message

Virginia Chu

unread,
Jul 6, 2017, 2:21:06 PM7/6/17
to geomorph R package
Hi everyone,
I am still new to R and very new to geomorph. I have been reading through the guide and trying to get things rolling.

I have digitized landmarks on mosquito wings from the CLIC - Coo software. The wing orientation in the images is inconsistent. I tried to image the wings along an x axis, but some were imaged along a y axis and everything in between. The attached image is from a gpagen plot of 13 landmarks. How can I orient all of the landmarks information to be consistent?

Also, I have lots of grouping information. I am not sure how to add it to my landmark data.

Attached is my landmark data and grouping information.

My code:
mydata<-readland.tps("Field 13 LM test1.txt", specID = "ID")
classifier<- read.csv("Specimen grouping.csv", header=T)

Thanks,
Virginia
Field 13L gpagen plot.jpeg
Field 13 LM test1.txt
Specimen grouping.csv

Adams, Dean [EEOBS]

unread,
Jul 6, 2017, 3:52:14 PM7/6/17
to Virginia Chu, geomorph R package

Virginia,


There are several issues here; primarily in the format of your TPS file.

 

First, you need to remove extraneous information after scale; specifically " PIXELS = 1 MM"  .  A simple ‘find/replace’ will let you do this in any text editor.  Once removed the file will read into geomorph correctly.

 

Then you need to ‘link up’ the classifier data with the specimens. This requires names in both files which are identical.  Your names are in the image names, but you need to remove some things, such as the path, and the ‘.gif’.  Also, note that in the TPS file images had a space in the names ‘APR 001’ while in the classifier they did not ‘APR001’.  These must be the same in both or you cannot link up the classifiers with the landmark data.


I did a quick fix of your file to read it in and reproduce the gpagen image you had. From this I suspect that orientation of your specimens under the camera was not the issue. Instead, I suspect that some specimens are flipped relative to others (righties and lefties).  This looks to be the case visually, and when I examine the maximal shape distance between specimens, it is enormous, and not biologically reasonable.


Another possibility is that you digitized some landmarks out of order; meaning that the homology of landmarks between specimens is not the same (landmark 4 is now thought to be landmark 5 for instance).

 

I suggest you examine all of these digitizing issues, then try running things in the script below. After that, linking up the shape data with other variables can be accomplished using hints in the geomorph user guide:

 

https://github.com/geomorphR/geomorph/raw/gh-pages/geomorph%20user%20guide/Quick_Guide_to_Geomorph-3.0.pdf

 

Best, Dean

 

##

library(geomorph)

  mydata<-readland.tps("Field 13 LM test1.txt", specID = "imageID")

classifier<- read.csv("Specimen grouping.csv", header=T)

 

gpa.res<-gpagen(mydata)

plotAllSpecimens(gpa.res$coords)

 

 

max(dist(two.d.array(gpa.res$coords)))  #huge maximal Procrustes distance. Something not right in digitizing

dim(gpa.res$coords)  #241 individuals

dim(classifier) #244 rows

 

Dr. Dean C. Adams

Professor

Department of Ecology, Evolution, and Organismal Biology

       Department of Statistics

Iowa State University

www.public.iastate.edu/~dcadams/

phone: 515-294-3834

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/074d7ad1-49b4-4807-bf3c-c61e13c74168%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Virginia Chu

unread,
Jul 7, 2017, 1:58:50 PM7/7/17
to geomorph R package, vir...@gmail.com
Hi Dean,
Thank you very much for the help!
I cleaned up my data and the matching specimen information. I tried to use left wings whenever possible but found 12 right wings. I removed them and got a new plot (attached). I also ran the maximal Procrustes distance and it went from 1.6436 to 1.6411. 

These specimens while the same species are from a large range of places and have different wing lengths that I have already measured. I have a lot more wings to digitize so I'm trying to troubleshoot a little more.

1. Would flipping the right wings to be measured in the same orientation as the left allow me to add them to my analysis?
2. I have been dealing with the .txt files I get from CLIC. Is there another file method that I can use to better handle my data? Should I use something other than CLIC?
3. Do I need to re-digitize these wings?

Thanks,
Virginia

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.
To post to this group, send email to geomorph...@googlegroups.com.

Fwings ex right 13L.jpeg

Adams, Dean [EEOBS]

unread,
Jul 7, 2017, 3:48:44 PM7/7/17
to Virginia Chu, geomorph R package

Virginia,

From the PDistances I strongly suspect that you still have some left-right issues in the dataset.

 

Incidentally, if you can identify which are rights and you wish to flip them to be lefts, that is easy: just multiply one of the coordinates (x or y) by -1 for those specimens. An example below:

 

 

Mydata[,1,which(side=="r")] <- Mydata[,1,which(side=="r")]* -1  vv#reflect 'g'

 

This last line reflects the x-coordinates of all right-specimens to now be left-looking specimens, where:

 

Mydata = a 3D array of landmark coordinates for the specimens

Side =  a vector of R and L for each specimen

 

Dean

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--

You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.

Adams, Dean [EEOBS]

unread,
Jul 7, 2017, 3:51:32 PM7/7/17
to Virginia Chu, geomorph R package

Virginia,

 

A few other thoughts for identifying the rights and lefts.

 

First, one could try plotOutliers, which plots Procrustes distances from each specimen to the average. If only a few specimens are rights and the rest are lefts, the average should be closer to the lefts, and the few right-handed specimens will show up as the largest outliers.

 

Second, one could take the gpa-aligned specimens and plot them one at a time.  There you will be able to see which ones look ‘flipped’ relative to the others.

 

Generally, it is more cumbersome to identify these issue post-digitizing, but it is possible.


Dean

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--

You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.

Jeremy Gibson

unread,
Mar 16, 2018, 11:15:16 AM3/16/18
to geomorph R package
Hi all, 

So I am running into a similar issue with my 3D dataset. For some reason X coordinates are getting flipped and at the moment I can not identify the culprit. I've checked all the source files and their coordinates, I have also plotted each individual before GPA and all are aligned correctly. However, after GPA, several of my samples have their x-coordinate flipped (y and z seem to be okay). I'm worried that mean plots and the GPA composite of all samples may be influenced by these flipped coordinates. These coordinate flips create real problems when trying to compare deformation patterns resulting in useless data. Has anyone else run into this problem? Is there a solution? I would hate to have to force flip the coordinates of just flipped samples while others seem fine.

Fig1: 2D raw landmarks (z-axis removed) - red dot is the same LM tracked across all three figures.

Fig 2: 2D coordinates after GPA for the same individual in Fig 1.

Fig 3: 2D mean shape for the group that individual 6 belongs. Notice the mean shape is flipped (position of the red dot) in relation to Fig 2. All GPA 2D coordinates from all individuals from this group are oriented as in Fig 2, so why is the mean shape flipped?




Cheers,
Jeremy

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.


To post to this group, send email to geomorph...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Adams, Dean [EEOBS]

unread,
Mar 16, 2018, 5:58:02 PM3/16/18
to geomorph-...@googlegroups.com

Jeremy,

 

The GPA function in geomorph will not automatically reflect specimens during the analysis (one form of flipping). What I meant in my earlier post was that some of the specimens may be digitized as R or L.  Combining them makes little sense in their original; one must reflect them prior to GPA.

 

Note that your 2D view of these by simply excising the Z coordinate is not a perfect way to see any issues, because GPA will rotate in all 3 dimensions. Thus the X,Y,Z axes are not the same before and after GPA.

 

I suggest you examine closely your original specimens to ensure that they are not ‘righties’ and ‘lefties’ before combining them and submitting them to a GPA.

 

Dean

 

Dr. Dean C. Adams

Director of Graduate Education, EEB Program

Professor

Department of Ecology, Evolution, and Organismal Biology

       Department of Statistics

Iowa State University

www.public.iastate.edu/~dcadams/

phone: 515-294-3834

 

Hi all, 

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--

You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.

Jeremy Gibson

unread,
Mar 19, 2018, 6:32:08 AM3/19/18
to geomorph R package
Dean,

Thank you for the reply and the insightful comments. I have verified that all my samples are correctly registered and aligned in the same direction, so this likely isn't the cause; additionally, I don't have 'righties' they are all lefties. I knew that after GPA analysis the resulting coordinates are a product of the superimposition process and this is what is concerning to me (or worry). My data is split up into several different populations but when I do a GPA across all specimen, they seem to all be in the same orientation; however, if separated into their populations, after GPA the realignment is very apparent (x-coordinates flipped for some individuals resulting in population means to be flipped). This issue creates a serious problem when trying to draw comparisons between the populations, as vector plots reveal the "flip" in coordinates and results in useless (comparable) data.

If this is the case with some populations being flipped - any suggestions on how to realign all of the samples so that comparisons between populations makes sense?

Thanks - Cheers,
Jeremy

Hi all, 

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.


To post to this group, send email to geomorph...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Mike Collyer

unread,
Mar 19, 2018, 7:42:26 AM3/19/18
to geomorph-...@googlegroups.com
Jeremy,

You might consider not aligning your specimens to their principal components or just recognize that if you do these analyses separately for each population, an arbitrary outcome might make the alignment of one group turned 180 degrees compared to another.  This is a common outcome with PCA.  The principal components can be turned 180 degrees and the result is no different (you just change the way you look at it).  It just looks different because it is happening arbitrarily by group.

Why you are running GPA separately on groups and attempting to compare populations is a whole other problem that you should reconsider.  I’m not sure I understand the logic in that.

Cheers!
Mike

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.

Jeremy Gibson

unread,
Mar 19, 2018, 8:16:57 AM3/19/18
to geomorph R package
Mike,

Thank you for the quick reply. In my overall analysis, I'm using the superimposition from GPA to investigate the effects of population and other covariates on shape with ProcD.lm. However, in order to understand how each population differs from each other I generate mean shapes for each population to compare using plotRefToTarget. Perhaps this has been the problem. I suppose that instead of regenerating the superimposition or using mshape by each population, I could pull out, from the original overall GPA, the aligned coordinates for individuals and separate them by population and generate a mean this way. This could work, as in the larger GPA, the point cloud doesn't seem to show signs of specimen flipping. I never thought about doing it this way because I thought it would be better to generate mean shapes from each population separately. Does this approach sound reasonable? 

Cheers,
Jeremy
Mike

Mike Collyer

unread,
Mar 19, 2018, 8:28:51 AM3/19/18
to geomorph-...@googlegroups.com
Jeremy,

The function, coords.subset, has an example on the help page to do exactly what you wish to do. There is no reason to secondarily run GPA on your separate populations. In fact, there are several arguments for why not to do this, one of which you have already discovered.

Good luck!
Mike

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Adams, Dean [EEOBS]

unread,
Mar 19, 2018, 10:21:07 AM3/19/18
to geomorph-...@googlegroups.com

Jeremy,

 

Mike caught an important component that I missed in your posts: the separate GPA. Definitely do not do this. Instead, a single GPA of all specimens followed by subsetting as Mike suggested is what is appropriate.

 

Note also that one can obtain the group means from an anova model using advanced.procD.lm. That is yet another approach to getting where you wish to be.


Good luck,

 

Dean

 

Dr. Dean C. Adams

Director of Graduate Education, EEB Program

Professor

Department of Ecology, Evolution, and Organismal Biology

       Department of Statistics

Iowa State University

www.public.iastate.edu/~dcadams/

phone: 515-294-3834

 

Mike



Hi all, 

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/28b6a33a-1845-42a1-adbe-eae015424df7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.
To view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/183273ca-d08e-46ef-b998-ae0eb4ca54da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-pack...@googlegroups.com.
To post to this group, send email to geomorph-...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Jeremy Gibson

unread,
Mar 19, 2018, 11:11:10 AM3/19/18
to geomorph R package
Mike and Dean,

Thanks so much for the comments - Yep, the population based PGA was definitely the problem. Now with individuals separated out by population from the overall GPA, all samples and mean shapes are oriented in the same direction - yeah! Now looking back at my code - it is a very good lesson to pass things by others - I got into a coding zone and just applied GPA analysis to each population and didn't think anything more about - that is until I wanted to start comparing mean shapes. Fortunately, I was not using those results in my overall statistical models. Thanks so much for the quick feedback - very much appreciated! 

Cheers,
Jeremy  

Mike



Hi all, 

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.


To post to this group, send email to geomorph...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

--
You received this message because you are subscribed to the Google Groups "geomorph R package" group.

To unsubscribe from this group and stop receiving emails from it, send an email to geomorph-r-package+unsub...@googlegroups.com.


To post to this group, send email to geomorph...@googlegroups.com.
Visit this group at https://groups.google.com/group/geomorph-r-package.

Reply all
Reply to author
Forward
0 new messages