david-barnett / microViz

R package for microbiome data visualization and statistics. Uses phyloseq, vegan and the tidyverse. Docker image available.
https://david-barnett.github.io/microViz/
GNU General Public License v3.0
102 stars 11 forks source link

Hierarchical clustering in relative abundances plots #50

Closed BrigittevdG closed 2 years ago

BrigittevdG commented 2 years ago

Hello David,

In the correlation heatmaps from the microViz package, hierarchical clustering using euclidean distances is shown on top/next the heatmap. Is it also possible to include the hierarchical clustering in the relative abundances plots? And would it be possible to get the clusters with the use of the Bray-Curtis dissimilarity (which is already used for the order of the relative abundances plot)?

Kind regards, Brigitte

david-barnett commented 2 years ago

Hi Brigitte,

Not currently possible unfortunately, but could be a nice feature for the future. If you really need it, the code from inside ps_seriate can get you the seriation object which has the clustering dendrogram inside it. You could then plot this alongside the bar chart with ggdendro or dendextend http://andrie.github.io/ggdendro/

(but indeed this would be a bit of manual work)

Code below adapted from inside ps_seriate

method = "OLO_ward"
dist = "bray"
tax_transform = "identity"

# transform taxa for ordering 
ps_transformed <- ps_get(tax_transform(ps, trans = tax_transform))

# calculate distance between samples
distMat <- dist_get(dist_calc(data = ps_transformed, dist = dist))
ser <- seriation::seriate(x = distMat, method = method)

Out of interest, why do you want the clustering dendrogram?

BrigittevdG commented 2 years ago

Hi David, Thanks for the suggestion! I want the clustering to see if there are some groups visible based on the microbiome composition. I am going to try to use your suggestion. Thanks!