taxon_colours: Generate a colour for each taxon

View source: R/taxon_colours.R

taxon_coloursR Documentation

Generate a colour for each taxon

Description

This function creates a named colour for each taxon in a phyloseq object at a specified taxonomic level.

Usage

taxon_colours(
  ps_obj,
  tax_level,
  merged_label = "Other",
  merged_clr = "grey90",
  palette = NULL,
  base_clr = "#008CF0"
)

Arguments

ps_obj

A phyloseq object

merged_label

The label of the merged taxa (usually "Other")

merged_clr

The colour to assign to the merged taxa

palette

A custom colour palette. Can be named.

base_clr

the colour from which to generate the palette if no palette is provided.

Details

If no palette is provided, colours are generated using the nested_palette function from the ggnested package. Only the taxonomic group with the merged_label will get a custom colour. If a palette is provided, its colours will replace the generated colours in the order in which they were specified. If a named palette is provided, they will be used to replace specific colours.

Value

A named character vector

Examples

data(GlobalPatterns)

# Get top taxa and generate a palette
top <- top_taxa(GlobalPatterns, n_taxa = 10)
pal <- taxon_colours(top$ps_obj, tax_level = "Phylum")
scales::show_col(pal)

# Generate a palette with a different base_clr
pal <- taxon_colours(top$ps_obj, tax_level = "Phylum", base_clr = "blue")
scales::show_col(pal)

# Provide a custom incomplete palette
pal <- taxon_colours(top$ps_obj, tax_level = "Phylum", palette = c("blue", "pink"))
scales::show_col(pal)

# Provide a custom incomplete named palette
pal <- taxon_colours(top$ps_obj, tax_level = "Phylum", palette = c(Cyanobacteria = "blue", Proteobacteria = "pink"))
scales::show_col(pal)


gmteunisse/Fantaxtic documentation built on June 7, 2024, 8:47 a.m.