joey711 / phyloseq

phyloseq is a set of classes, wrappers, and tools (in R) to make it easier to import, store, and analyze phylogenetic sequencing data; and to reproducibly share that data and analysis with others. See the phyloseq front page:
http://joey711.github.io/phyloseq/
582 stars 187 forks source link

Getting more than two axes with `ordinate` #1439

Open lvclark opened 3 years ago

lvclark commented 3 years ago

I'm doing NMDS with ordinate and trying to get three axes rather than two. I see in the documentation that I can set k = 3. This works with the Bray distance, but not with UniFrac or weighted UniFrac. It seems to be an issue with argument handling.

Error in UniFrac(physeq, ...) : unused argument (k = 3)
lvclark commented 3 years ago

I was able to work around this by calling phyloseq::distance followed by vegan::metaMDS.

elenu commented 3 years ago

Hi @Ivclark,

I had similar issue, and I managed by running this way and visualizing with scatterplot3d package. Maybe, you could adapt it to your case:

library("scatterplot3d") # load
nmds <- ordinate(physeq3, "NMDS", "bray", "unifrac", weighted=TRUE)
s3d <- scatterplot3d(nmds$species, angle = 55,type="h", 
                     main="3D NMDS",
                     xlab = "NMDS-1",
                     ylab = "NMDS-2",
                     zlab = "NMDS-3", pch = 16,size=6, 
                     grid=TRUE, box=FALSE)
s3d
text(s3d$xyz.convert(pcoa$species), labels = rownames(nmds$points),
     cex= 0.7)
TonyMane commented 3 years ago

greetings @lvclark, i'm a bit new to phyloseq, was wondering if you could describe the code/function you developed to get a 3-ordination and subsequent plot out for phyloseq.

lvclark commented 3 years ago

Hi @TonyMane in this particular case I did

dist_unifrac <- phyloseq::distance(ps_prop, "unifrac")
nmds_unifrac <- vegan::metaMDS(dist_unifrac, k = 3)

See https://github.com/HPCBio/plotly_microbiome, a package I made for making 3D plots from the output. Install then do ?beta_diversity_3d.

TonyMane commented 3 years ago

thanks, much appreciated. One question, it doesn't seem to handle the output of nmds_unifrac from above: beta_diversity_3d(nmds_unifrac) Error in data.frame(x$points[, 1:3], metadata[, color.column], Label = rownames(x$points)) : argument "metadata" is missing, with no default

lvclark commented 3 years ago

Please see the help page. In that case you would be using the method for monoMDS and so you need to provide values for the metadata and color.column arguments.

TonyMane commented 3 years ago

greetings, was just wondering if there was any way to plot these directly to a pdf file. I run all the commands and get the 'index.html' files to plot, then export as a .png file. But it would be ideal to have .pdf files.

lvclark commented 3 years ago

@TonyMane See if this helps https://plotly.com/r/static-image-export/

RachBioHaz commented 1 year ago

Hi @TonyMane in this particular case I did

dist_unifrac <- phyloseq::distance(ps_prop, "unifrac")
nmds_unifrac <- vegan::metaMDS(dist_unifrac, k = 3)

See https://github.com/HPCBio/plotly_microbiome, a package I made for making 3D plots from the output. Install then do ?beta_diversity_3d.

Hi, I'm a new user of plotly_microbome and new(ish) to bioinformatics. Can I suggest the help page contains information on the data structure of your examples? Thanks

lvclark commented 1 year ago

@RachBioHaz I made that package mostly for internal use at an old job, so I'm not maintaining it any more. But ps_prop would be a phyloseq object with abundances converted to proportions.