highlight_by_node: Highlight Nodes in a Phylogenetic Tree with Custom Fill...

View source: R/HighlightByNode.R

highlight_by_nodeR Documentation

Highlight Nodes in a Phylogenetic Tree with Custom Fill Colors and Transparency

Description

This function adds highlights to specific nodes in a phylogenetic tree represented by a 'ggtree' object. Users can specify the nodes to highlight along with custom fill colors, transparency, and extension options.

Usage

highlight_by_node(
  ggtree_object,
  nodes,
  fill_colors,
  alpha_values,
  extend_values
)

Arguments

ggtree_object

A 'ggtree' object representing the phylogenetic tree.

nodes

A character vector specifying the nodes to highlight.

fill_colors

A character vector specifying the fill colors for the highlighted nodes.

alpha_values

A numeric vector specifying the transparency values for the highlighted nodes (between 0 and 1).

extend_values

A logical vector specifying whether to extend the highlight to the whole clade below each node.

Value

A modified 'ggtree' object with the specified nodes highlighted.

Examples

plot_file <- system.file("extdata", "tree_plot.rds", package = "TransProR")
p2_plot <- readRDS(plot_file)

# Please replace the following vectors with your specific values
nodes <- c(117, 129, 125, 127, 119,
           123, 139, 166, 124, 131, 217) # x-values of the nodes you want to highlight
fill_colors <- c("#CD6600", "#CD6600", "#CD6600",
                 "#CD6600", "#009933", "#009933",
                 "#009933", "#009933", "#9B30FF",
                 "#9B30FF", "#9B30FF") # Fill colors
alpha_values <- c(0.3, 0.3, 0.3, 0.3, 0.2, 0.3,
                  0.3, 0.3, 0.3, 0.3, 0.3) # Transparency values
extend_values <- c(25, 24, 24, 25, 25, 25,
                   24, 24, 25, 24, 24) # Values for the 'extend' parameter

p2 <- highlight_by_node(
  p2_plot,
  nodes,
  fill_colors,
  alpha_values,
  extend_values
)

TransProR documentation built on April 4, 2025, 3:16 a.m.