grunwaldlab / grunwaldlab/metacoder

Adding color to nodes based on specific values of observations.

Open
#210 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
148
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Based on my current workflow, I'm generating a taxmap object with metacoder. And then I'm plotting the tree like this:

# Phyloseq...
# Data manipulation....
# Data manipulation....
# Metacoder/Taxmap
...
heat_tree(title = sprintf("Bacterial Abundance at %s Level", rank_list[[i]]),
              # NODE
              ## The node size is relevant to the Abundance level
              ## The node color is relevant to wheather the abundance is higher in control vs stressed animals
              ## The node labels are relevant to significant taxon names.
              node_size = n_obs,
              node_color = log2_median_ratio,
              node_label = ifelse(wilcox_p_value < 0.05, taxon_names, NA),
              node_label_size = 1,
              ### The color red indicates higher abundance in Stressed animals
              ### The color blue indicates higher abundance in Control animals
              ### The color grey represents no difference in Control vs Stressed abundance
              ### Colorblind node_color_range = c("navy", "grey80", "greenyellow"),
              ### Colorblind node_color_range = c("navy", "grey80", "yellow3"),
              node_color_range = c("blue", "grey90", "red"),
              node_color_trans = "linear",
              node_color_interval = c(-4, 4),
              node_size_axis_label = "Size: Number of OTUs",
              node_color_axis_label = "Color: Increased in Stressed (red) vs.\n Increased in Control (blue)\n",
              ### The labels are only for significant (pvalue < 0.05) abundance changes
              ### The labels are green to offset the blue/red colors.
              node_label_color = wilcox_p_value,
              node_label_color_range = c("darkgreen"),
              node_label_max = 1000,
              # EDGE (Branch)
              ## The edge size is relevant to the level of abundance.
              ## The edge color is relevant to significant levels of abundance.
              edge_color = wilcox_p_value,
              ### The color interval is set from 0 to 1 (p-value is a percentage).
              ### The color range is a vector consisting of a dark color followed 
              ### by 19 of the same color.  This divides the interval by 20 so that
              ### every edge below 0.05 (5%; 1/20) is the dark color.  
              ### So our p-value is the dark color.
              edge_color_range = c("honeydew2", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50"),
              edge_color_trans = "linear",
              edge_color_interval = c(0, 1),
              edge_size_axis_label = "Size: Number of OTUs",
              edge_color_axis_label = "Color: Significant Changes \nAmong Treatments", 
              # PLOT Options
              initial_layout = "reingold-tilford",
              layout = "davidson-harel", 
              repel_labels = TRUE, 
              repel_force = 3,
              overlap_avoidance = 3, 
              make_edge_legend=FALSE)

For my edge_color you can see that I did some fairly hacky things. As you can see below I wanted to use the p value (<0.05 is grey50) to color the edges. In order to do this I set my interval up with c(0,1), and the color range is a list with the significant color (honeydew2), and 19 other values (grey50).
While I'm aware I could probably use edge_color = ifelse(wilcox_p_value < 0.05, 0, 1) and edge_color_range = c("honeydew2", "grey50"), this works for now and is irrelevant to my point.

## The edge size is relevant to the level of abundance.
              ## The edge color is relevant to significant levels of abundance.
              edge_color = wilcox_p_value,
              ### The color interval is set from 0 to 1 (p-value is a percentage).
              ### The color range is a vector consisting of a dark color followed 
              ### by 19 of the same color.  This divides the interval by 20 so that
              ### every edge below 0.05 (5%; 1/20) is the dark color.  
              ### So our p-value is the dark color.
              edge_color_range = c("honeydew2", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50", "grey50"),
              edge_color_trans = "linear",
              edge_color_interval = c(0, 1),

My main concern is the node color:

             ## The node labels are relevant to significant taxon names.
              node_color = log2_median_ratio,
              ### The color red indicates higher abundance in Stressed animals
              ### The color blue indicates higher abundance in Control animals
              ### The color grey represents no difference in Control vs Stressed abundance
              ### Colorblind node_color_range = c("navy", "grey80", "greenyellow"),
              ### Colorblind node_color_range = c("navy", "grey80", "yellow3"),
              node_color_range = c("blue", "grey90", "red"),
              node_color_trans = "linear",
              node_color_interval = c(-4, 4),

According to the docs for the heat_tree object in the color section:

Colors

The colors of nodes, edges, labels, and trees can be mapped to arbitrary numbers. This is useful for highlighting groups of taxa. Only the relative size of numbers is used, not the values themselves.

Is there any way to set up the node color scale so that the numbers represent the actual values (log2_median_ratio in my case), and so that the colors span the desired ranges (negative numbers are red, positive are blue in my case)? Or is there at least a way to map the node_color_interval to the actual data?

My current plans are to add a column to the diff_table using (using mutate_obs) that contains :
<Taxon_name (log2_median_ratio)>
And then I'll use that variable as the node_label. And this will at least let us see the corresponding values.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the heat_tree color-mapping entry point and review the color section of its documentation, especially node_color, node_color_range, node_color_trans, and node_color_interval. Determine how numeric values are normalized and identify the tests or examples covering color scales. Done means node colors can use the actual log2_median_ratio range, including negative and positive values, with the documented interval behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.