Qiime2R PCoA plotting and understanding explained variance

Hi @TukelSB ,

Can you clarify what you mean by:

The biplot would look something like this:

This biplot is taken directly from the q2-DEICODE tutorial here and uses Emperor. The arrows are the taxa loadings and are not just numbers, they are visualized.

As for adding 3D plots, I would advise caution against this because a) more often than not the 3rd PC does not really add much information to the plot, though of course there are exceptions, b) 3d plots in publications can get rather messy and of course you can't really see in the 3rd dimensions anyways.
I'll also add that you can simply export the 3D plot from emperor as an .svg and modify it anyway you want using your favorite program (ex illustration, inkscape).

That being said, if you wanted to make a 3D version of this for exploring there are lots of options in R, one of them is with the plot_ly :package:.

Here I'm just using the Moving Pictures tutorial data.

library(tidyverse)
library(qiime2R)
library(plotly)

#import data
metadata<-read_q2metadata("sample-metadata.tsv")
uwunifrac<-read_qza("unweighted_unifrac_pcoa_results.qza")
shannon_div<-read_qza("shannon_vector.qza")$data %>% 
  rownames_to_column("SampleID") 


#create joint dataframe
dat <- uwunifrac$data$Vectors %>%
  select(SampleID, PC1, PC2, PC3) %>%
  left_join(metadata) %>%
  left_join(shannon_div)

# 3D Plot with plot_ly
plot_ly(dat, x= ~PC1, y= ~PC2, z= ~PC3, 
        type="scatter3d", mode="markers", color= ~`body-site`, size= ~`shannon`,
        marker = list(sizemode = 'diameter'),
        text = ~paste('Body site:', `body-site`, 
                      '<br>Shannon Diversity:', `shannon`,
                      '<br>Antibiotic use:', `reported-antibiotic-usage`)
        ))

Which gives something like this:

test3d.html (4.8 MB)

If you want to add the biplot vectors that'll take some more customization but at that point it's honestly just easier to export and modify the Emperor plot.

3 Likes