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

Exclude labels of lowest taxon_rank #367

Open
fionnualabulman opened this issue Oct 15, 2024 · 1 comment
Open

Exclude labels of lowest taxon_rank #367

fionnualabulman opened this issue Oct 15, 2024 · 1 comment

Comments

@fionnualabulman
Copy link

fionnualabulman commented Oct 15, 2024

Hello and thanks for the great package.

I am producing a heat tree matrix of differential relative abundances in fungal taxa. I would like to display differences in taxa down to the order rank, however including the labels for this rank makes the figure unreadable. Is there a way to exclude all labels for this rank only (keeping labels for class, phyla & kingdom)?

I have read the FAQ "The labels are too small!" but hope there is another option instead of selectively suppressing them with "dont_print".

I have tried to filter "cleaned_names" for taxon_ranks = "o" but this produces an error as the vectors are no longer the same length:

obj %>%
+   metacoder::filter_taxa(taxon_ranks == "o", supertaxa = TRUE, reassign_obs = c(diff_table = FALSE)) %>%
+   mutate_obs("cleaned_names", 
+              gsub(taxon_names, pattern = "\\[|\\]", replacement = "")) %>%
+   filter_obs("cleaned_names", taxon_ranks != "o") %>%
+   metacoder::filter_taxa(grepl(cleaned_names, pattern = "^[a-zA-Z]+$"), reassign_obs = c(diff_table = FALSE)) %>%
+   heat_tree_matrix(data = "diff_table",
+                    node_label = cleaned_names,
+                    node_label_size = 7 * (n_obs / max(n_obs)),  # Adjust based on the number of OTUs
+                    node_size = n_obs,
+                    node_color = log2_median_ratio, # difference between groups
+                    node_color_trans = "linear",
+                    node_color_interval = c(-3, 3), # symmetric interval
+                    edge_color_interval = c(-3, 3), # symmetric interval
+                    node_color_range = c("cyan", "gray", "magenta"), # The color palette used
+                    node_color_axis_label = "Log 2 ratio of median counts",
+                    node_size_axis_label = "Number of OTUs",
+                    node_size_range = c(0.02, 0.04),
+                    node_label_size_range = c(0.02, 0.04),
+                    layout = "da", initial_layout = "re",
+                    key_size = 0.67,
+                    seed = 2)
Adding a new "character" vector of length 162.
Error: TRUE/FALSE vector (length = 57) must be the same length as the number of taxa (162)

Thanks for your help with this.

@zachary-foster
Copy link
Contributor

Hi, thanks! Does this do what you want?

library(metacoder)
#> This is metacoder version 0.3.7 (stable)

x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
                   class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
                   class_regex = "^(.+)__(.+)$")

heat_tree(
  x, 
  node_label = ifelse(taxon_ranks == "g", '', taxon_names),
  node_size = n_obs,
  node_color = n_obs
)

Created on 2024-10-15 with reprex v2.1.1

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

No branches or pull requests

2 participants