adegenet
adegenet copied to clipboard
method for sorting compoplot by population?
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.
@MycoPunk would it be too much trouble to ask for a reproducible example?
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
...
here my plot script:
compoplot(dapc, posi="bottomright",txt.leg=paste("Cluster", 1:4), lab="", ncol=2, xlab="individuals")
Thanks for your help !
I don't know if it still works, but you might want to try {ggcompoplot}: https://github.com/zkamvar/ggcompoplot#readme
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))