Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCoA extract scores #515

Open
yakshiUPR opened this issue Aug 19, 2015 · 6 comments
Open

PCoA extract scores #515

yakshiUPR opened this issue Aug 19, 2015 · 6 comments

Comments

@yakshiUPR
Copy link

Greetings,

I am working on a microbiomes project and did an principal coordinates analysis in Phyloseq with the following script:

ordu = ordinate(qd.red, "PCoA", "unifrac", weighted = TRUE)
p = plot_ordination(qd.red, ordu, color = "SampleType", shape = "Geology")
p = p + scale_y_continuous(limits=c(-0.2, 0.2))
p = p + geom_point(size = 3)
p = p + scale_colour_brewer(type = "qual", palette = "Set1")
p

It works great, but I would like to add environmental data (found on the mapping file) and species vectors to see what explains better the apparent arrangement of the ordination.
Also, is there a way to extract the scores associated to the ordination.

Thanks in advance for any comments,
Yakshi Ortiz

@joey711
Copy link
Owner

joey711 commented Sep 9, 2015

PCoA Scores

The ordu object is already a list that has these scores built in. You can see the relevant documentation describing each element in the list at the documentation page for the MDS/PCoA, linked from within the ordinate functions doc.

?ordinate

Alternatively, if you already know what to expect and/or what you're looking for, you can just use the $ operator to access the component of your choice. RStudio does autocompletion of list element names, so you can just start typing and you'll start to see what pops up. The str function is also built for this kind of object exploration

# RStudio and list autocomplete
ordu$[press tab]
# OR use str on the list itself
str(ordu)

Species/Taxa Positions

Please see
http://joey711.github.io/phyloseq/plot_ordination-examples
It contains some examples of the "split" or "biplot" option within plot_ordination. These already do the work of either extracting species scores (e.g. if you used correspondence analysis) or calculating the weighted average of species positions according to abundance across samples, which would be needed for your example where the PCoA is based entirely on the w-UniFrac distance matrix.

Sample covariates

There is not currently an option in plot_ordination for overlaying all sample covariates from the sample_data component onto a plot. There are some non-ggplot2 ways of doing this with the vegan package, but I don't have any demos of that handy. This would be a nice feature, and a separate issue post that I could flag as a feature request.

@joey711 joey711 closed this as completed Sep 9, 2015
@mw55309
Copy link

mw55309 commented Oct 19, 2021

Hi

I am having the exact same problem, and I have read and re-read the documentation and there isn't an obvious solution.

I have an object ord_clr which was produced using ordinate(..., method="rda") and I cannot for the life of me extract any data from it (thought plot_ordination works)

Is there any chance of more documentation for this? Please :-D

Thanks
Mick

@vmikk
Copy link

vmikk commented Oct 19, 2021

Hello!

As a workaround, you may extract scores with plot_ordination, just add justDF = TRUE:

sc <- plot_ordination(..., justDF = TRUE)

The first two columns should be the scores.
If you need species scores as well, run:

sc <- plot_ordination(..., type = "biplot", justDF = TRUE)

Alternatively, you may use scores function from the vegan package:

ord_clr <- ordinate(..., method = "RDA")
sc <- vegan::scores(ord_clr)

In sc, there should be scores for species (sc$species) and sites (sc$sites).

With kind regards,
Vladimir

@mw55309
Copy link

mw55309 commented Oct 19, 2021

Thank you!

@spholmes
Copy link
Contributor

spholmes commented Oct 19, 2021 via email

@joey711
Copy link
Owner

joey711 commented Nov 3, 2021

@spholmes oops! Maybe we should make the method argument case insensitive? And also a warning/error when method doesn't match to anything expected...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants