phyloseq icon indicating copy to clipboard operation
phyloseq copied to clipboard

Getting more than two axes with `ordinate`

Open lvclark opened this issue 4 years ago • 10 comments

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 avatar Feb 04 '21 15:02 lvclark

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

lvclark avatar Feb 04 '21 16:02 lvclark

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)

elenu avatar Feb 09 '21 13:02 elenu

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.

TonyMane avatar Jun 23 '21 15:06 TonyMane

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.

lvclark avatar Jun 23 '21 16:06 lvclark

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

TonyMane avatar Jun 23 '21 20:06 TonyMane

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.

lvclark avatar Jun 23 '21 21:06 lvclark

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.

TonyMane avatar Aug 10 '21 18:08 TonyMane

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

lvclark avatar Aug 13 '21 02:08 lvclark

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

RachBioHaz avatar Apr 20 '23 02:04 RachBioHaz

@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.

lvclark avatar Apr 26 '23 13:04 lvclark