gl.pcoa.plot - individual & pop labels together

323 views
Skip to first unread message

Gabriella Scatà

unread,
Oct 10, 2022, 10:29:39 PM10/10/22
to dartR
Hi,
I was just wondering whether it is possible to add the possibility to label points in the PCA plot by individual, but color by population (or by another field with as.pop=() ).

In the previous dartR version (v. 1.9.6), this was possible by including the argument "labels = ind"  and the dots where automatically assigned the population colour.

It was actually very useful to be able to have both individual labels and colour by a different parameter (pop or species or other) in the PCa plot.

Just a suggestion!
Thanks a lot
Best,
Gabriella

Jose Luis Mijangos

unread,
Oct 10, 2022, 11:28:56 PM10/10/22
to dartR
Hi Gabriella,

When a dataset contains a large number of individuals, the visualisation of each individual's label in a PCoA plot is not optimum. As a solution, we provide an interactive option in which you can display information of each point by moving your cursor over it. As an example, check the code below.

Cheers,
Luis

library(dartR)
# performing PCoA
pcoa <- gl.pcoa(platypus.gl)
# names of individual metrics
names(platypus.gl$other$ind.metrics)
# plotting PCoA using sex as population and using the interactive option
# to visualise individual names
gl.pcoa.plot(pcoa,
             platypus.gl,
             as.pop = "sex",
             interactive = TRUE,
             pop.labels = "legend")

thaisr...@gmail.com

unread,
Oct 10, 2022, 11:33:16 PM10/10/22
to dartR
Hi,

I will use this post to ask for a related matter. In the previous version of dartR the plot function returned a ggplot object. The same doesn't happen anymore with the new version. I am struggling to define the xlim and ylim (I would like to have both in the same size) of the plot because they are not parameters that can be defined in the plot default. Is there any way of producing a ggplot object out of the the 'gl.pcoa.plot' function or any  argument that can be used to edit the xlim and ylim of the plot? 

Thank you,
Thais

Jose Luis Mijangos

unread,
Oct 10, 2022, 11:51:26 PM10/10/22
to dartR
Hi Thais,

You could try the code below.

Cheers,
Luis

library(dartR)
library(ggthemes)

test <- platypus.gl
pcoa <- gl.pcoa(test)
# running the function with save2tmp = TRUE to save the plot and tables in
# the temporal directory
gl.pcoa.plot(pcoa,test,save2tmp = TRUE)
# listing the plots and tables in tempdir
gl.list.reports()
# choosing the plot or table to retrieve
res <- gl.print.reports(1)
# selecting color for the populations
PopColours <- gl.select.colors(test,library =  "brewer",palette = "Set3",)
# modifying the plot
res +
  theme_bw() +
  ylim(4,-4)+
  xlim(4,-4)
 

Gabriella Scatà

unread,
Oct 11, 2022, 2:49:15 AM10/11/22
to dartR
Thank you Luis,
I know about the interactive option, but I just find it easier and more convenient to have all the individual labels in the plot (or at least as many as possible) at the same time, especially when presenting a PCA plot.
This is especially convenient when looking at points in the PCA which spread away from the main clusters...I would end up having to check each point in the interactive view and then report the labels manually myself in this case.
It is possible, just less convenient than having the option to report the individual labels directly in the plot, if that makes sense.

Anyways, I do understand that this is not a major issue at the moment.
Thanks anyways,
Best,
Gabriella

thaisr...@gmail.com

unread,
Oct 11, 2022, 4:33:50 AM10/11/22
to dartR
Brilliant! 
Thank you very much Luis for both the solution and the fast reply! :)

Cheers,
Thais

Jose Luis Mijangos

unread,
Oct 12, 2022, 8:21:58 PM10/12/22
to dartR
Hi Gabriella,

You could try the code below to add labels to individuals. We will take into account your suggestion to add this option in the next release of dartR.

Cheers,
Luis

library(dartR)
library(directlabels)


test <- platypus.gl
pcoa <- gl.pcoa(test)
# running the function with save2tmp = TRUE to save the plot and tables in
# the temporal directory
gl.pcoa.plot(pcoa,test,save2tmp = TRUE,pop.labels ="none")

# listing the plots and tables in tempdir
gl.list.reports()
# choosing the plot or table to retrieve
res <- gl.print.reports(1)
# adding labels to individuals
res +
  directlabels::geom_dl(aes(label = ind),
                        method = list("first.points",
                                      cex = 1))

Carlo Pacioni

unread,
Oct 12, 2022, 10:45:50 PM10/12/22
to da...@googlegroups.com
I'm with Gabriella on this.

Luis, see my email "gl.pcoa.plot" on 04/05/2022. Maybe we can resume this conversation next time we catch up?

cheers,
carlo


--
You received this message because you are subscribed to the Google Groups "dartR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/7a6cb59d-9eab-455f-a6c8-e770fae2ba6cn%40googlegroups.com.

Gabriella Scatà

unread,
Oct 13, 2022, 1:17:10 AM10/13/22
to dartR
Hi Luis,
thank you for the code and thank you for taking my suggestion into consideration.

Honestly, so far I have been using the old function from the previous dartR version (1.9.6) because it allows to set labels = individuals and then it colours by population.
I have just been using that piece of code I shared some time ago to switch between 2 versions of dartR whenever I need a function from the old dartR or from the developer version of dartR...

But yeah it would be more convenient to have all these options in one function :)

Thanks for the code anyways i'll try that out!
Best,
Gabriella

Reply all
Reply to author
Forward
0 new messages