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 groupssplit_legend — Extract legend as separate grob and combine with patchworkgenerate_colorsGenerate 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_legendExtract 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)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.