create_cell_colors: Create a cell color pallet for plots

View source: R/create_cell_colors.R

create_cell_colorsR Documentation

Create a cell color pallet for plots

Description

This function returns a character() vector with valid R colors for a given input character() of unique cell types. These were colors that have been useful in our experience.

Usage

create_cell_colors(
  cell_types = c("Astro", "Micro", "Endo", "Oligo", "OPC", "Excit", "Inhib", "Other"),
  pallet_name = c("classic", "gg", "tableau"),
  pallet = NULL,
  split = NA,
  preview = FALSE
)

Arguments

cell_types

A character() vector listing unique cell types.

pallet_name

A character(1) indicating choice of included pallets:

  • "classic": classic set of 8 cell type colors from LIBD, checked for visability and color blind accessibility. Default pallet.

  • "gg" : mimic colors automatically picked by ggplot.

  • "tableau" : 20 distinct colors from tableau color pallet, good for large number of cell type.

pallet

A character() vector listing user provided color pallet. If provided, overrides pallet selection with pallet_name.

split

delineating character(1) after which suffixes will be ignored. This is useful for cases when say A.1 and A.2 are both to be considered fine subtypes of broad cell type A (here split = "\\."). When used the function returns a nested list of borad and fine cell types.

preview

A logical(1) indicating whether to make a plot to preview the colors.

Value

A named character() vector of R and hex color values compatible with ggplot2:scale_color_manual().

Examples

## create cell colors with included pallets
create_cell_colors(pallet_name = "classic")
create_cell_colors(pallet_name = "classic", preview = TRUE)
create_cell_colors(pallet_name = "tableau", preview = TRUE)

## use custom colors
my_colors <- c("darkorchid4", "deeppink4", "aquamarine3", "darkolivegreen1")
create_cell_colors(cell_type = c("A", "B", "C", "D"), 
                   pallet = my_colors, 
                   preview = TRUE)
                   
## use Rcolor brewer
create_cell_colors(cell_type = c("A", "B", "C"), 
                   pallet = RColorBrewer::brewer.pal(n = 3, name = "Set1"),
                   previe = TRUE)

## Options for subtype handling
## Provide unique colors for cell subtypes (DEFAULT) - returns one level list
create_cell_colors(
    cell_types = c("A.1", "A.2", "B.1", "C", "D"),
    pallet_name = "classic",
    preview = FALSE
)

## Provide gradient colors for A.1 and A.2 by using the "split" argument
## returns a nested list with broad & fine cell type colors, fine cell types
## are gradient with the top level matching the broad cell type
create_cell_colors(
    cell_types = c("A.1", "A.2", "B.1", "C", "D"),
    split = "\\.",
    pallet_name = "classic",
    preview = TRUE
)

## try with custom colors
create_cell_colors(
    cell_types = c("A.1", "A.2", "B.1", "C", "D"),
    split = "\\.",
    pallet = my_colors,
    preview = TRUE
)


LieberInstitute/DeconvoBuddies documentation built on Feb. 15, 2025, 12:06 p.m.