obj <- taxmap(taxon_ids = LETTERS[1:18],
                  supertaxon_ids = c(NA, "A", "A", "A", "B", "B", "C", "C", "D", "F", "F", "K", 
"J", "J", "H", "H", "I", "G"))

plot_one <- function(obj, subset, highlight, title = deparse(match.call()[[3]])) {

  ids <- obj$taxon_data$taxon_ids
  vc <- rep("#EEEEEE", length(ids))
  vc[ids == highlight] <- "#999999"
  vc[ids %in% subset[[1]]] <- "lightblue"
  obj$taxon_data$my_vc <- vc

  heat_tree(obj, node_label = taxon_ids,
     node_color = my_vc, 
     make_legend = FALSE,
     edge_color = "#EEEEEE",
     node_size = 1 / n_supertaxa,
     node_size_range = c(0.06, NA),
     title = title,
     title_size = 0.05, 
     node_color_range = c("#555555", "#EEEEEE"))
}


gridExtra::grid.arrange(ncol = 4, nrow = 1,
                        plot_one(obj, supertaxa(obj, "F", recursive = FALSE),
                                 highlight = "F", "Parent"),
                        plot_one(obj, supertaxa(obj, "F"),
                                 highlight = "F", "Supertaxa"),
                        plot_one(obj, subtaxa(obj, "F", recursive = FALSE),
                                 highlight = "F", "Children"),
                        plot_one(obj, subtaxa(obj, "F"),
                                 highlight = "F", "Subtaxa"))


grunwaldlab/metacoder documentation built on Feb. 22, 2024, 3:47 a.m.