as.pop not working in gl.pcoa.plot

162 views
Skip to first unread message

Mandi D'Ombrain

unread,
Mar 30, 2022, 2:10:27 AM3/30/22
to dartR
Hello, 

I recently updated to the new dartR version 2.0.3. I was previously using the standard CRAN version I believe (not the dev version). I'm running R 4.1.2. 

The argument as.pop in gl.pcoa.plot doesn't seem to be working. I've included an example with testset.gl.

Where I used to use the following:
pc <- gl.pcoa(testset.gl)
gl.pcoa.plot(pc,  testset.gl  , labels="pop", as.pop = "sex", theme_plot = 1)

I'd now use: 
pc <- gl.pcoa(testset.gl)
gl.pcoa.plot(pc, testset.gl, pop.labels = "pop", as.pop = "sex")

While this runs without any errors, the labels are still the original pop data, and I don't get the message of 'temporarily setting pop to sex as per the as.pop parameter'. It also won't produce a fatal error if given a value for as.pop that does not match the ind.metrics.

Also, less importantly, while the new arguments for changing colours/size will be useful, I liked the option to change the theme as well and this seems to have been removed. 

Kind regards, 
Mandi

Jose Luis Mijangos

unread,
Mar 30, 2022, 4:26:35 AM3/30/22
to dartR
Hi Mandi,

Thank you for reporting the first bug from version 2 : )

I can think of two options to solve it, also some code to change the theme of the plot:

library(dartR)
# option 1
# define population before using pcoa
test <- testset.gl
pop(test) <- test$other$ind.metrics$sex
pc <- gl.pcoa(test)
gl.pcoa.plot(pc, test, pop.labels ="pop")

# option 2
# install the updated version from my github branch
gl.install.vanilla.dartR(flavour = "dev_luis")
library(dartR)

pc <- gl.pcoa(testset.gl)
gl.pcoa.plot(pc, testset.gl, pop.labels = "pop", as.pop = "sex")

# changing theme
library(ggthemes)
# Plot themes can be obtained from:
# https://ggplot2.tidyverse.org/reference/ggtheme.html} and \item
# https://yutannihilation.github.io/allYourFigureAreBelongToUs/ggthemes/

test <- testset.gl
pc <- gl.pcoa(test)
# saving plot and report to the temporal directory (tempdir) using save2tmp
gl.pcoa.plot(pc, test, save2tmp = TRUE)
# listing files in tempdir and identify the plot you want to recover
gl.list.reports()
# recovering plot number one
plot_1 <- gl.print.reports(1)

#changing the plot
plot_1 + theme_dark()

Cheers,
Luis

Mandi D'Ombrain

unread,
Mar 30, 2022, 7:11:42 PM3/30/22
to dartR
Hi Luis, 

Working perfectly now with your updated version, thank you! 

Thank you for the theme code as well, although I've found that setting the active theme with theme_set() first works too! 

Cheers, 
Mandi

Gabriella Scatà

unread,
Aug 16, 2022, 10:34:50 PM8/16/22
to dartR
Hi Luis,
I have been having this problem too.

I don't seem able to use the "as.pop" argument.
I would like to colour/label the points by individual or by species name (which is an extra field  column I added in the individual metadata), but I don't seem able to make it work.

I also tried to install the developert@dartR version (2.1.1), but it still doesn't work and I get the folowing error:

"Error in gl.pcoa.plot(dataset1_PCA,  :
  argument 5 matches multiple formal arguments
"


Code below:
<
 gl.pcoa.plot(
                dataset1_PCA  ,
                dataset1  ,
                scale = FALSE,
                ellipse = FALSE,
                p = 0.95,
                labels = "pop",
                as.pop = "ind",    # I also tried using "Species" (my species column in the individual metadata, used with or without " "), and "dataset1@other[["ind.metrics"]][["Species_dartR"]]" (with or without " ")
                verbose = 5
              )


But the message I get is always the same:
"Error in gl.pcoa.plot(dataset1_PCA,  :
  argument 5 matches multiple formal arguments
"

I did not try to install your dartR version (as you suggested in the post above): gl.install.vanilla.dartR(flavour = "dev_luis"), because you said in another reply to one of my posts that the gl.install.vanilla.dartR() function doesn't work?

Is there a solution for labelling the points in the PCA plot by individual/other metrics at the moment?

Thanks a lot as usual!
Best,
Gabriella

Jose Luis Mijangos

unread,
Aug 17, 2022, 12:38:01 AM8/17/22
to dartR
Hi Gabriella,

We have identified the bug, which should be fixed by tomorrow morning.

In the meantime, you could assign the population before performing the PCoA analysis, as shown in the code below. Note that the parameter "p" is now "plevel" and the parameter "labels" is now "pop.labels".

Cheers,
Luis

# Installing CRAN version
install.packages("dartR")
library(dartR)

t1 <- platypus.gl
# assigning population
pop(t1) <- as.factor(t1$other$ind.metrics$Sex)
pcoa <- gl.pcoa(t1)

gl.pcoa.plot(pcoa,
             t1,

             scale = FALSE,
             ellipse = FALSE,
             plevel = 0.95,
             pop.labels = "pop",
             verbose = 5
)

Gabriella Scatà

unread,
Aug 18, 2022, 2:49:12 AM8/18/22
to dartR
Hi Luis, 
thanks for this alternative option...although running the PCA on each of my datasets takes over an hour (is that normal??), so I will try this option for one of the datasets, but I will wait for the plotting argument "as.pop" to be fixed to plot all the other datasets...

I will need to install the developer@dartR version to have the updated version of the function "gl.pcoa.plot" with the argument "as.pop" working? 
      [with devtools::install_github("green-striped-gecko/dartR@dev",build_vignettes = TRUE) , correct?

Finally, I had a question on the argument "parallel" in the function "gl.pcoa": in the help section of this function, it says that this option is not working on Windows. Is that correct?
Could I use the package "parallel" in conjunction with the dartR function "gl.pcoa" to get faster PCA analysis?

Thanks a lot
Best,
Gabriella

Gabriella Scatà

unread,
Aug 18, 2022, 2:53:46 AM8/18/22
to dartR
Also, just to check, to have the most updated version of the developer dartR version, I would nee to re-install it every time, is that correct?

Meaning that, if I had installed the current developer version (2.1.1) a few days before, and now you fixed the bg in the "gl.pcoa.plot", I need to re-install the developer version to ensure I have the version from github with the bug fixed, correct?

Thanks again,
Gabriella

Gabriella Scatà

unread,
Aug 18, 2022, 9:31:38 PM8/18/22
to dartR
Hi Luis,
I just wanted to let you know that I tried the alternative option you suggested: saving the gl object dataset as a test dataset and then recoding the populations as the metric I want to have the points labelled by (i.e Species in my case), but I still get the same error message:

"Error in gl.pcoa.plot(test_dataset_blacktip_PCA, test_dataset_blacktip,  :
  argument 5 matches multiple formal arguments
"

I don't understand why "argument 5" matches multiple argument...that would be the "plevel" argument, but I think it means the "pop.labels" argument because only when I change the content of that argument to something that is not the real populations (i.e. individuals is, or Species name), I get this error message.

 Is there anything else I can try while you guys fix the problem?
Please let  me know when the gl.pcoa.plot function is updated in the dartR@developer version, so I can re-install the developer version and try again.

Thanks a lot!
Best,
Gabriella

Jose Luis Mijangos

unread,
Aug 18, 2022, 9:54:07 PM8/18/22
to dartR
Hi Gabriella,

The updated version of the gl.pcoa function, with the option "as.pop" activated, is already on the developing version which you can install using:

devtools::install_github("green-striped-gecko/dartR@dev",build_vignettes = TRUE)

How fast run the functions depends on the characteristics of your computer.

I run gl.pcoa on my PC (8 cores @ 3.1 GHz and 64GB RAM) using a dataset of 300 individuals and 45,000 SNPs and the option parallel = TRUE. The analysis took 844 seconds.

Cheers,
Luis

Jose Luis Mijangos

unread,
Aug 18, 2022, 10:06:42 PM8/18/22
to dartR
Hi Gabriella,

Note that the parameter "p" is now "plevel" and the parameter "labels" is now "pop.labels". 

When using a function, you should just use the parameters that you want to change, all the other values will use the default values. For example:

t1 <- platypus.gl
pcoa <- gl.pcoa(t1)
gl.pcoa.plot(pcoa, x=t1,
as.pop="Sex", verbose = 5)

It would be easier to help you if you could send a reproducible example, as mentioned at the top of this forum.

Cheers,
Luis




Gabriella Scatà

unread,
Aug 19, 2022, 1:13:29 AM8/19/22
to dartR
Thank you Luis,
now that alternative approach works! I have been jumping back and forth from the older dartR version to the current one, and I didn't realized I was using the syntax of the previous version. Thanks for noticing!

Anyways, looking forward to the argument "as.pop" working in the developer dartR version. Please let me know when that is ready
Thanks a lot!
Gabriella
Reply all
Reply to author
Forward
0 new messages