Open pig-raffles opened 3 years ago
It's been a while scince i didn't use Phyloseq but i managed to find some code:
ordinate <- ordinate(phyloseq_object, method ="PCoA", distance= "bray")
p <- plot_ordination(phyloseq_object, ordinate, justDF = T)
sample.id is a column of your p object containing the ids of your samples, if you do not have one in your metadata table, make sure to build it before you run your code
ggplot(data=p, aes(x=Axis.1, y=Axis.2, label= sample.id)) +
geom_point(size= 3) +
geom_line() +
geom_text(vjust = 0, nudge_y = 0.01, size=3)+
labs(x="PC1", y= "PC2")
Hope that helps.
Just in case the above solution didn't work for anyone else -- for me (phyloseq version 1.38.0):
plot_ordination(phyloseq_object, ordinate, justDF = T)
didn't generate a column with sample.id to use as a label. Ended up duplicating my row names as a new column.
sample_data(phyloseq_object)['sample_id'] <- row.names(sample_data(phyloseq_object))
# generate ordination and plot
ordcap <- ordinate(phyloseq_object, "CAP", "bray", ~study_group)
plot_ordination(phyloseq_object, ordcap, "samples", label="sample_id") + theme_minimal()
Thanks a lot @aemann01. I get the id samples in my phyloseq plot!!
Hi,
This is again probably a simple issue but is there a way to get the row names/numbers from the sample data section of the phyloseq object as a label for data points in ordination plots?
This would allow me to identify outlier samples far quicker
Thanks, again