Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with plot_tree function #1445

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

ycl6
Copy link

@ycl6 ycl6 commented Feb 26, 2021

PR to fix some issues with the current plot_tree function:

  1. When using the method="treeonly", the taxonomyTable type in the data.table will cause the below issue when including tip labels. See plot_tree: combining "treeonly" with taxonomy table or instead have only one geom_point per leaf? #1042 and plot_tree from phyloseq missing branches names #796
plot_tree(gps, method = "treeonly", label.tips = "Phylum", text.size = 3)
Don't know how to automatically pick scale for object of type taxonomyTable. Defaulting to continuous.
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'object' in selecting a method for function 'tax_table': incorrect number of dimensions
  1. When using the method="sampledodge", some tip labels would be missing due to abundance filtering with the unsorted data.table. See Missing labels in plot_tree #749 and plot_tree, label.tips = "taxa_names" doesn't display if a sample = 0 #475
plot_tree(gps, method = "sampledodge", color = "SampleType", label.tips = "Phylum", text.size = 3)
  1. The tip label spacing from the point is different in branches with and without adjacent point (example in Missing labels in plot_tree #749)
  2. The 'a' text superimposed with colored points in legend

Usage examples

library(phyloseq)
data(GlobalPatterns)
gps = tax_glom(GlobalPatterns, "Phylum")

plot_tree(gps, method = "treeonly", label.tips = "Phylum", text.size = 3)
plot_tree(gps, method = "treeonly", size = "Abundance", label.tips = "Phylum", text.size = 3)
plot_tree(gps, method = "treeonly", size = "Abundance", color = "Kingdom", label.tips = "Phylum", text.size = 3)

plot_tree(gps, method = "sampledodge", color = "SampleType", label.tips = "Phylum", text.size = 3)
plot_tree(gps, method = "sampledodge", size = "Abundance", justify = "left", label.tips = "Phylum", text.size = 3)
plot_tree(gps, method = "sampledodge", size = "Abundance", color = "SampleType", justify = "left", label.tips = "Phylum", text.size = 3)

@Fedorov113
Copy link

Thank you very much, this saved me a lot of time and nerves! Works like a charm.

@MoniaLo
Copy link

MoniaLo commented Apr 27, 2022

Actually I didn't fix the problem.
I'm trying to do a phytree from a phyloseq obj.
So that, every time I do use justify= "yes please", it will be cut some species (label.tip) from my tree. Instead, when I don't add the justify all the species show up. That's, I guess, because when there is not the presence in the first sample, it doesn't give the name also in the remaining samples (in my case: Compartment). But, I really would like to add justify because the plot is more clear to see.
This is my code:

plot_tree(species, color="Order", shape = "Compartment", label.tips = "Species", ladderize="left", justify="left", title="Proteobacteria")

where:
species = subset_taxa(ps, Phylum == "Proteobacteria")

I put a pic to make it clear of the plot with and without justify.
AllSpecies
MissingSpecies
Thanks

@ycl6
Copy link
Author

ycl6 commented May 3, 2022

Hi @MoniaLo

The PR should allow text labels to be justified.

Using the example dataset GlobalPatterns, only 4 tree tips were not labeled because they are missing the "Genus" annotation, as demonstrated by labelling the tree tips by taxa ID, and also as seen in the tax_table.

library(ggplot2)
library(phyloseq)
library(cowplot)

data(GlobalPatterns)

clean <- prune_taxa(taxa_sums(GlobalPatterns) > 0, GlobalPatterns)
sub <- subset_taxa(clean, Order == "Desulfovibrionales")

a <- plot_tree(sub, color = "Family", shape = "SampleType", label.tips = "taxa_names", text.size = 3,
               ladderize = "left", justify = "left", title = "Desulfovibrionales") + scale_shape_manual(values = 1:9)
b <- plot_tree(sub, color = "Family", shape = "SampleType", label.tips = "Genus", text.size = 3,
               ladderize = "left", justify = "left", title = "Desulfovibrionales") + scale_shape_manual(values = 1:9)

plot_grid(a, b, ncol = 1)

tax_table(sub)[is.na(tax_table(sub)[,"Genus"]),]
#> Taxonomy Table:     [4 taxa by 7 taxonomic ranks]:
#>        Kingdom    Phylum           Class                 Order
#> 147645 "Bacteria" "Proteobacteria" "Deltaproteobacteria" "Desulfovibrionales"
#> 137367 "Bacteria" "Proteobacteria" "Deltaproteobacteria" "Desulfovibrionales"
#> 361169 "Bacteria" "Proteobacteria" "Deltaproteobacteria" "Desulfovibrionales"
#> 201363 "Bacteria" "Proteobacteria" "Deltaproteobacteria" "Desulfovibrionales"
#>        Family                Genus Species
#> 147645 "Desulfovibrionaceae" NA    NA
#> 137367 "Desulfovibrionaceae" NA    NA
#> 361169 "Desulfovibrionaceae" NA    NA
#> 201363 "Desulfovibrionaceae" NA    NA

Created on 2022-05-03 by the reprex package (v2.0.1)

@MoniaLo
Copy link

MoniaLo commented May 9, 2022

In my case, my samples don't miss in the annotations, so all the label tips (Species) should show up. So, as you can see from my pictures, everytime I add the justify command ("left" or "yes please"), some label.tip, and so, some Species miss on my tree (you can perfectly see that the last annotation, for example, Bdellovibrio bacteriovorus in greenish doesn't show up in the second plot). To be more clear, even if I set the label tip with taxa_name, some ASV will not show up because of justify, not because of the missing value.

@ycl6
Copy link
Author

ycl6 commented May 15, 2022

Hi @MoniaLo Would you like to provide a small dataset for me to test the plot_tree function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants