inst/docs/en/reference/colors-legend.md

Colors & Legend

Generate color-blind-safe palettes and split legends for publication-ready plots.

This module contains the following functions:

generate_colors

Generate color mapping for taxonomic groups

Usage:

generate_colors(groups, palette = "viridis", color_mapping = NULL)

Arguments:

| Argument | Description | |----------|-------------| | groups | Character vector of group names | | palette | Palette name (e.g., "viridis", "Set1", "rainbow") or color vector | | color_mapping | Named vector of specific color assignments (highest priority) |

Value:

Named color vector (names = groups)

Examples:

groups <- c("Firmicutes", "Proteobacteria", "Bacteroidetes")
generate_colors(groups, palette = "viridis")

split_legend

Extract legend as separate grob and combine with patchwork

Usage:

split_legend(p, ncol_split = 2)

Arguments:

| Argument | Description | |----------|-------------| | p | ggplot object | | ncol_split | Number of columns for legend splitting (used for reflow) |

Value:

patchwork object. Note: This returns a patchwork object, not a ggplot object. You cannot add ggplot2 layers with + after calling split_legend(). Use patchwork operators like | and / for layout composition.

Examples:

data(example_tree)
p <- plot_timetree(example_tree, rank = "phylum")
split_legend(p, ncol_split = 2)

中文 | 文档首页



Try the Rclade package in your browser

Any scripts or data that you put into this service are public.

Rclade documentation built on Sept. 26, 2026, 5:07 p.m.