library(metacoder)
#> Loading required package: taxa
#> This is metacoder verison 0.3.3 (stable)
# Parse data for example
x <- parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
class_regex = "^(.+)__(.+)$")
# Calculate the taxon abundance for each numeric column (i.e. sample)
x$data$tax_abund <- calc_taxon_abund(x, "tax_data")
#> No `cols` specified, so using all numeric columns:
#> 700035949, 700097855, 700100489 ... 700102367, 700101358
#> Summing per-taxon counts from 50 columns for 174 taxa
# Make function to plot presence/absence for one sample
plot_one_sample <- function(id) {
heat_tree(x,
node_label = taxon_names,
node_size = n_obs,
node_color = ifelse(x$data$tax_abund[[id]] > 0, 'red', 'grey'),
title = id)
}
# Plot presence/absence for each sample
sample_plots <- lapply(hmp_samples$sample_id[1:3], plot_one_sample)
sample_plots[[1]]

sample_plots[[2]]

Created on 2019-11-20 by the reprex package (v0.3.0)