Closed najibveto closed 2 years ago
Hi @najibveto ,
The plot_taxa_heatmap
is only for OTU/ASV level data. It does not support aggregated data. If you want to have genus-level data with clustering you can try our new TreeSE based tools here: https://microbiome.github.io/OMA/viz-chapter.html#viz-chapter.
If you want to do it in phyloseq, then I have an in-house set of tools which are focused for our data analysis but should work widely.
https://github.com/RIVM-IIV-Microbiome/biomeUtils and https://github.com/RIVM-IIV-Microbiome/biomeViz are under development.
This plot function relies on TidyHeatmap and ComplexHeatmap
# install two tools
devtools::install_github("RIVM-IIV-Microbiome/biomeUtils")
devtools::install_github("RIVM-IIV-Microbiome/biomeViz")
# load
library(biomeUtils)
library(biomeViz)
library(microbiome)
library(dplyr)
data("FuentesIliGutData") # example data
ps <- FuentesIliGutData
# ps <- phyloseq
# tax_tb <- as(tax_table(ps),"matrix") %>%
# as.data.frame() %>%
# rownames_to_column("ASV") %>%
# mutate(Genus.Species = ifelse(!is.na(Species), paste0(Genus, ".", Species), Species)) %>%
# select(-Species) %>%
# rename(Species = Genus.Species)
#
# #tax_tb[1:30, 5:9]
# rownames(tax_tb) <- tax_tb$ASV
# tax_tb <- tax_tb[,-1]
#
# tax_table(ps) <- tax_table(as.matrix(tax_tb))
# you can input your phyloseq here
top_genera_w_mean_relabund <- ps |>
aggregate_taxa("Genus") |>
microbiome::transform("compositional") |>
findTopTaxa(top= 30, method="mean")
# check the top five
top_genera_w_mean_relabund[1:5]
# For CLR-based plot
ps.clr <- ps %>%
aggregate_taxa("Genus") |>
microbiome::transform("clr")
# Select top taxa to plot
ps.clr.top.30 <- phyloseq::prune_taxa(top_genera_w_mean_relabund, ps.clr)
plotTidyHeatmap(ps.clr.top.30,
select_taxa = top_genera_w_mean_relabund,
group_samples_by = "ILI",
add_taxa_label = FALSE,
cluster_rows = FALSE,
.scale = "none",
transform = NULL,
palette_value = c("red", "white", "blue"),
# Adjust taxa name size
row_names_gp = grid::gpar(fontsize = 6, fontface="italic"))
Hope this helps. PS: You should think of cleaning your taxa table for cleaner and clearer outputs. Cheers, Sudarshan
hello, I generate the heatmap using the following code:
however, the column names are double instead of single name: how to correct the code to have only a single name? the taxa table is as follow:
thank you.