microbiome / miaViz

Microbiome Analysis Plotting and Visualization
https://microbiome.github.io/miaViz
Artistic License 2.0
10 stars 12 forks source link

Fix layout problem in plotRowTree #56

Closed TuomasBorman closed 2 years ago

TuomasBorman commented 2 years ago

Fix layout problem

library(mia)
library(miaTime)
library(miaViz)

data(hitchip1006)
tse <- hitchip1006

# Add relative abundances
tse <- transformSamples(tse, method = "relabundance")

altExp(tse,"Phylum") <- agglomerateByRank(tse, "Phylum")
rowData(altExp(tse,"Phylum"))$prevalence <- 
    getPrevalence(altExp(tse,"Phylum"), detection = 1/100, sort = FALSE,
                  assay_name = "counts", as_relative = TRUE)

altExps(tse) <- splitByRanks(tse)
altExps(tse) <-
    lapply(altExps(tse),
           function(y){
               rowData(y)$prevalence <- 
                   getPrevalence(y, detection = 1/100, sort = FALSE,
                                 assay_name = "counts", as_relative = TRUE)
               y
           })
top_phyla <- getTopTaxa(altExp(tse,"Phylum"),
                        method="prevalence",
                        top=5L,
                        assay_name="counts")
top_phyla_mean <- getTopTaxa(altExp(tse,"Phylum"),
                             method="mean",
                             top=5L,
                             assay_name="counts")
x <- unsplitByRanks(tse, ranks = taxonomyRanks(tse)[1:6])
x <- addTaxonomyTree(x)

p <- plotRowTree(x[rowData(x)$Phylum %in% top_phyla,],
                 edge_colour_by = "Phylum",
                 tip_colour_by = "prevalence",
                 layout = "slanted",
                 node_colour_by = "prevalence") + theme(legend.position = "none")  

p