Does anyone know how to replicate the output of the old plotTangentSpace function?

373 views
Skip to first unread message

Russell Engelman

unread,
Dec 27, 2020, 8:16:11 PM12/27/20
to geomorph R package

Dear Geomorph Group,

I wrote a script using geomorph in R that I planned to publish as part of a study in order for other researchers to modify and expand upon with their own data. Unfortunately, I had to reinstall geomorph due to an unrelated computer problem, and when I reinstalled geomorph I found that my old code would no longer work due to the plotTangentSpace function being depreciated.

I know how to run an analogous analysis by using the gm.prcomp function, but one thing I found is that the new gm.prcomp function (including plot.gm.prcomp) does not produce the summary figure that plotTangentSpace does. I found the old plotTangentSpace function to be very useful in providing an initial summary graphic of the first two axes and their extreme shapes, even if I ended up using a more customized graphic for actual publication. Plot.gm.prcomp does not provide an easy way to color-code datapoints by adding an additional argument the way plotTangentSpace did with the "labels" argument, and it does not provide the helpful deformation grids showing the minima and maxima shapes of each axis the way plotTangentSpace did. The attached picture is the result I get when I try to plot the results of a gm.prcomp object in R.

I realize I could probably replicate the results of plotTangentSpace using ggplot2 and plotReftoTarget, but I am trying to figure out if there is an easier way to replicate the results of this deprecated function without writing up a new, complex code in ggplot2() or plot(). Alternatively if there is no other option, does anyone know a way to replicate the way the old summary figure function worked?

Sincerely,

Russell

Rplot02.jpeg

Antigoni Kaliontzopoulou

unread,
Dec 28, 2020, 3:40:08 AM12/28/20
to geomorph-...@googlegroups.com

Russell,

I believe the answers to all your questions are included in the gm.prcomp help page, including examples of how to colour code observations depending on a grouping variable. The extremes of the PC axes can be plotted using plotRefToTarget. More extensive explanations are included in the vignette "geomorp.PCA", just run: vignette("geomorph.PCA"). The rest is learning how to control layout() and arrows() and you can make a plot exactly like those previously made by plotTangentSpace, and much more.

gm.prcomp substituted plotTangentSpace PRECISELY to allow users to customize the plots whichever way they want.

Good luck!

Antigoni

--
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 view this discussion on the web, visit https://groups.google.com/d/msgid/geomorph-r-package/5b971e16-f5f3-4689-a6c5-ec16404b9945n%40googlegroups.com.
-- 
Antigoni Kaliontzopoulou 

Auxiliary Researcher
CIBIO/InBIO, Centro de Investigação em Biodiversidade e Recursos Genéticos
University of Porto
Campus Agrário de Vairão, 4485-661 Vairão
PORTUGAL

https://sites.google.com/view/akaliontzopoulou/home
https://cibio.up.pt/research-groups-1/details/phenevol
http://cibio.up.pt/people/details/akaliont
http://www.seh-herpetology.org/

Russell Engelman

unread,
Dec 30, 2020, 1:56:14 AM12/30/20
to geomorph R package
Dear Dr.  Kaliontzopoulou  ,

I have looked over the vignettes for plot.gm.prcomp and I didn't see anything about how to accomplish any of these things in there. The only information in there was how to include things like node labels or plot the resulting data as a 3D figure with phylogeny on the third axis. It seems like all of those arguments have been passed to plot() if anything but this is not clear.

It seems kind of ridiculous that I need to need to waste 16-25 lines of code trying to replicate the plot, whereas before I could get the results from a single command (i.e.: plotTangentSpace(df,groups=df$group)). It seems even worse that the code originally worked as typed, except now I have to manually rewrite the code so that it will do again what it once did automatically before. So now my code is non-replicable in the middle of the manuscript being under review for publication. On top of that, if plotTangentSpace doesn't work I have to same the extremes of PC1-2 as additional objects to plot which results in four more objects per permutation of my analysis cluttering up my global environment. Especially since I'm not looking to customize my plot to make a publication-quality figure, I just want to produce a crude summary figure to allow the user to see and troubleshoot the the initial results of the morphometric analysis. 

On top of that, I’m not even sure if it’s possible to combine objects from plot() and ggplot2(). I remember trying to combine plotReftoTarget didn't work with ggplot2 when I tried them some time before because one uses plot() as its base function and the other creates a ggobject and the two do not work together. Looking up how to do this in R in places like StackOverflow generally gets people telling you "don't bother doing it, just to everything in ggplot2", but you can't make geomorphic morphometric shape diagrams using ggplot2, you have to use plotReftoTarget, which leaves one up a creek. I get that such a thing isn’t specifically a geomorph issue but it causes problems because if the plotTangentSpace function no longer works it is more efficient to create scatter plots in ggplot2 but then I cannot add the results of plotReftoTarget to the resulting figure to create something like what plotTangentSpace created before. I remember what I ended up doing was recreating the figure in Photoshop of all programs, which took a lot of time.

It’s just kind of frustrating that I had code that worked and now I have to waste a whole bunch of extra time and effort reinventing the wheel in order to fix something that wasn't broken instead of focusing on getting the manuscript done. The plotTangentSpace was really helpful to me, and it was also useful in helping me make sure I didn't have points misplaced or the initial geometric morphometric file input corrupted. It's especially frustrating because this was the kind of thing one had to do by hand all the way back in 2015 and the entire point of the plotTangentSpace function was to simplify this workflow. The new geomorph essentially sends us back to those days. This kind of change to geomorph is honestly pretty unhelpful.

Sincerely,
Russell


Antigoni Kaliontzopoulou

unread,
Dec 30, 2020, 5:54:06 AM12/30/20
to geomorph-...@googlegroups.com

Russell,

I am sorry to hear that you are unhappy with the changes implemented in geomorph. I can assure you that this is not a personal conspiracy of the geomorph team against you, but rather an intent to improve the routines implemented by the package and make it more flexible for more users. As is frequently the case in package development, it is not possible to make everyone happy. Note that the transition from plotTangentSpace to gm.prcomp was implemented to add a whole suite of analytical techniques to the package, and are not merely related to plotting. Nevertheless, also note that plot.gm.prcomp is an S3 function, meaning that one is able to pass any arguments that work in the base plot() function, thus providing full control for plotting.

As for your particular  case, I am not sure what to recommend. ggplot is not my field, so I cannot help there. If this is a one-case issue, you can try reverting back to an older version of geomorph that does have plotTangentSpace in it, and maybe even grabbing the code from that function so you do not have to re-write it yourself. Beware, however, that if you revert back you may need to also revert your R version or those of other packages, and that any corrections implemented since will not be available. This Rstudio article can be useful in that direction, and in understanding the implications, of installing an older version of any R package:

https://support.rstudio.com/hc/en-us/articles/219949047-Installing-older-versions-of-packages

Otherwise, I am sorry to say that this is the world of R: package developers make decisions and updates (the R-base package included) and the rest of us need to adapt to those changes.

Good luck with your article

Antigoni

Miriam Zelditch

unread,
Dec 30, 2020, 7:28:21 AM12/30/20
to geomorph R package
I initially hated that change because it meant changing all the scripts that I was using for teaching as well as for analyses I was doing. If what you miss is the way that the function laid out the plot (including those teeny deformed grids) then you could just copy out the function and you'd still have it. I did that, but I longer can recall where I put it because I have not used it in so long that it's out of my global mental environment. It does take two lines instead of one, although you could put it all in one if you want:
PCA<-gm.prcomp(apes.shape)
plot(PCA,pch=21,bg=apes.species,cex=1.5)





--
Miriam Zelditch
Associate Research Scientist
Museum of Paleontology
University of Michigan
Ann Arbor, MI  48109-1079

Mike Collyer

unread,
Dec 30, 2020, 9:10:11 AM12/30/20
to geomorph R package
Dear geomorph users,

I have one (in my opinion) important addendum to Miriam’s suggestion.  Instead of,

plot(PCA,pch=21,bg=apes.species,cex=1.5)

I suggest giving this object a name, e.g., 

pc.plot <- plot(PCA,pch=21,bg=apes.species,cex=1.5)

One can then use picknplot.shape with this object (pc.plot) to generate deformation grids anywhere in the plot (not just at the limits of PC 1) in an interactive manner.  This not only does what plotTangentSpace did, but enhances it without embedding deformation grids in the plot, a nuisance many users sought to overcome for years with plotTangentSpace.  Furthermore, in the gm.prcomp object (PCA), $shapes provides the configurations for the limits on every PC, in case someone would rather use plotRefToTarget to generate the types of deformation grids one finds at the limits of PC axes, allowing the complete flexibility of plotRefToTarget, which was difficult to do when plots were embedded within the PC plot with plotTangentSpace (see Miriam’s comment about “teeny deformed grids”).  The $plot.args object from the plot object (pc.plot) provides the plot arguments, in case someone would like to export these values to make their own plots, using ggplot2 or any other plotting function.

Although plotTangentSpace might have been a useful tool for many users, its limitations proved to be quite problematic.  This was especially true when users could neither manipulate plots in certain ways nor produce high-quality figures for publications.  Too often we had to try to help users develop code that circumvented plotTangentSpace and use prcomp + many intermediate steps + plotRefToTarget to get to the same place.  This old function did not allow ellipsis (…) argument use, which could be passed to plot S3 generics, and it couldn’t because the result actually embedded three plots.  The many issues with this function outstripped its limited practical appeal.

The newer function (gm.prcomp) now allows PCA, phyloPCA, PACA, and data standardization to be used, giving users much more flexibility and control.  Additionally, "16-35 lines of code" are not required to get back to the same place.  No more than three lines of code are required, including

1. Defining ordination (gm.prcomp)
2. Plotting ordination (plot)
3. Generating deformation grids (picknplot.shape)

Note that these code lines represent independent analytical goal are also more efficient, independently.  If one wants to change the points in a plot from black to red, for example, and then to blue, the second line of code can be altered without having to re-analyze data in step 1 (something that plotTangentSpace required).  One can also use png, tiff, jpeg, etc., to produce publication-quality images.  The ability to go from data exploration to producing images for publication was extremely streamlined as a result, Russell’s diatribe notwithstanding.

Finally, several people have asked about using ggplot2 in geomorph.  It should be clear, as Antigoni pointed out, that package dependencies are risky.  With many package dependencies, one is always updating their package to adapt to other package changes.  I agree that ggplot2 produces nice plots and its style of augmenting or manipulating plots is appealing, but that does not mean that from a programming point of view, using ggplot2 to produce the plots in geomorph is straightforward.  The nice thing about R is that someone can design their own package to take the plot arguments output from geomorph plot objects and combine it with ggplot2, if this is a worthy objective, and publish it via CRAN.  I encourage somebody to do this.  This person (or these people) would have to be ready to roll with the changes required when the packages on which theirs depend are updated. I hope somebody takes this on.  It would be a nice additional package for GM researchers to have.  It is just beyond my current capacity to take it on.  

Warm regards,
Mike

Mohamad Bazzi

unread,
Dec 30, 2020, 9:25:29 AM12/30/20
to geomorph R package

For what it’s worth, most if not all visualization tools provided in the Momocs package (also used for GM) are based on ggplot syntax. One can easily run any given analysis through geomorph and subsequently plot results with functions provided in Momocs without much coding effort.

/Mohamad



Från: geomorph-...@googlegroups.com <geomorph-...@googlegroups.com> för Mike Collyer <mlco...@gmail.com>
Skickat: den 30 december 2020 15:10:07
Till: geomorph R package
Ämne: [geomorph-r-package] On plotting in geomorph
 








När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/

E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: http://www.uu.se/en/about-uu/data-protection-policy

Adams, Dean [EEOB]

unread,
Dec 30, 2020, 9:38:20 AM12/30/20
to geomorph-...@googlegroups.com

Russell,

 

The tone of your discourse is entirely inappropriate for a public forum, and will not be tolerated.


We write and maintain geomorph as a volunteer effort for the community; it is not a part of our paid jobs. And as all R-users know, package maintainers have the duty to update their packages as base-R makes changes, and to make additional enhancements as they see fit. 

 

If you are unhappy with the current version of geomorph, simply use the old one or write your own package.

 

Dean

geomorph creator and maintainer

 

Dr. Dean C. Adams

Director of Graduate Education, EEB Program

Professor

Department of Ecology, Evolution, and Organismal Biology

Iowa State University

https://www.eeob.iastate.edu/faculty/adams/

phone: 515-294-3834

Miriam Zelditch

unread,
Dec 30, 2020, 10:03:25 AM12/30/20
to geomorph R package
I like the flexibility of geomorph for making publication plots.  I did not miss plotTangentSpace for that, just for the really quick plots for troubleshooting, until Mike teased me about the greater complexity of typing plot(gm.prccomp(data.shapes)) versus plotTangentSpace(data.shapes). Anyone who has seen my typing will realize that typing two closing parentheses challenges my skills, but I did have to admit that this is not  truly arduous. 

Reply all
Reply to author
Forward
0 new messages