adegenet icon indicating copy to clipboard operation
adegenet copied to clipboard

method for sorting compoplot by population?

Open MycoPunk opened this issue 3 years ago • 4 comments

Is there a method for ordering the populations in a dapc object for plotting using compoplot()? It seems to be plotting alphabetically by strain name rather than by population, and all my attempts to sort/order by population takes it out of the dapc data structure.

Rplot

MycoPunk avatar Nov 19 '20 19:11 MycoPunk

@MycoPunk would it be too much trouble to ask for a reproducible example?

romunov avatar Nov 23 '20 13:11 romunov

Hi, Here is my example because I have the same need. My dapc$posterior is sorted by samples and I want it sorted by percentage of assignment to a pop. >dapc$posterior sample1 5.576774e-13 7.292916e-38 9.992571e-01 7.428533e-04 sample2 6.319537e-09 1.826668e-35 6.515979e-01 3.484021e-01 sample3 6.702570e-13 2.868899e-31 5.803038e-06 9.999942e-01 sample4 1.656789e-11 2.807384e-39 9.999988e-01 1.239072e-06 sample5 3.802130e-11 2.723374e-37 9.962180e-01 3.781974e-03 ...

image

here my plot script: compoplot(dapc, posi="bottomright",txt.leg=paste("Cluster", 1:4), lab="", ncol=2, xlab="individuals")

Thanks for your help !

AdrienInfo avatar Jan 05 '21 16:01 AdrienInfo

I don't know if it still works, but you might want to try {ggcompoplot}: https://github.com/zkamvar/ggcompoplot#readme

zkamvar avatar Feb 14 '21 17:02 zkamvar

In case it's still helpful for anyone with the same question... the Man page for compoplot() indicates it will work with simple matrices as input. So it's rather trivial to simply export the posteriors as a matrix, then order on your column of choice (e.g.,, here I've just done in decreasing value of membership to population1):

my.dapc.out <- as.matrix(my.dapc$posterior)
my.dapc.sort <- my.dapc.out[order(my.dapc.out[,2],decreasing=FALSE,]
compoplot(my.dapc.sort,col.pal=funky(2))

kevin-oh avatar Jun 09 '23 11:06 kevin-oh