-
Notifications
You must be signed in to change notification settings - Fork 28
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
Customize sample order heat_tree_matrix? #323
Comments
Sorry for the delay. This would be a good option to have. I might have a solution that uses the factor level order, but I need to test it more. |
addresses #323 When an ordered factor is supplied to the `groups` argument of `compare_groups`, the order of levels is used to arrange the results. This can be used to change the order of groups when the output is used with `heat_tree_matrix`
I think I have a solution for you. I modified install.packages("devtools")
devtools::install_github("grunwaldlab/metacoder") and try running the code again, this time using an ordered factor for your grouping variable. Let me know if that works or not. Thanks! |
Thank you for your reply! I had a look at the obj$data$diff_table however, and if I order the column "treatment_1", it does give me the order I want. But it does work if I do the following:
|
Thanks for the update. Hmm, it is not intended to work that way. It might not be returning the right result. I will look into that. The changes I made are to the x <- parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
class_regex = "^(.+)__(.+)$")
# Convert counts to proportions
x$data$otu_table <- calc_obs_props(x, data = "tax_data", cols = hmp_samples$sample_id)
# Get per-taxon counts
x$data$tax_table <- calc_taxon_abund(x, data = "otu_table", cols = hmp_samples$sample_id)
# Reorder metadata for plotting
hmp_samples <- dplyr::ungroup(hmp_samples)
fct_order <- c("Saliva", "Skin", "Stool", "Throat", "Nose")
hmp_samples$body_site <- factor(as.character(hmp_samples$body_site),
levels = fct_order,
ordered = TRUE)
# Calculate difference between treatments
x$data$diff_table <- compare_groups(x, data = "tax_table",
cols = hmp_samples$sample_id,
groups = hmp_samples$body_site)
# Plot
heat_tree_matrix(x,
data = "diff_table",
node_size = n_obs,
node_label = taxon_names,
node_color = log2_median_ratio,
node_color_range = diverging_palette(),
node_color_trans = "linear",
node_color_interval = c(-3, 3),
edge_color_interval = c(-3, 3),
node_size_axis_label = "Number of OTUs",
node_color_axis_label = "Log2 ratio median proportions") |
Hi,
I am comparing abundance between 5 different salinity ranges (0-10, 10-15, 15-20, 20-25, and 25-36).
I am making a heattree with heat_tree_matrix() as follows:
And this is the output:
To get a better insight into the gradient, however, I would like the sample order to be as follows:
Is there a way to customize the order of the samples in the matrix? I already tried reordering the levels of the factor, but that didn't influence the matrix.
Best regards,
Luna
The text was updated successfully, but these errors were encountered: