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.

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

Arguments

cell_types

A character() vector listing unique cell types.

palette_name

A character(1) indicating choice of included palettes:

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

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

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

palette

A character() vector listing user provided color palette. If provided, overrides palette selection with palette_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 palettes
create_cell_colors(palette_name = "classic")
#> Creating classic palette for 8 broad cell types
#>     Astro     Micro      Endo     Oligo       OPC     Excit     Inhib     Other 
#> "#3BB273" "#FF56AF" "#663894" "#F57A00" "#D2B037" "#247FBC" "#E83E38" "#4E586A" 
create_cell_colors(palette_name = "classic", preview = TRUE)
#> Creating classic palette for 8 broad cell types

#>     Astro     Micro      Endo     Oligo       OPC     Excit     Inhib     Other 
#> "#3BB273" "#FF56AF" "#663894" "#F57A00" "#D2B037" "#247FBC" "#E83E38" "#4E586A" 
create_cell_colors(palette_name = "tableau", preview = TRUE)
#> Creating tableau palette for 8 broad cell types

#>     Astro     Micro      Endo     Oligo       OPC     Excit     Inhib     Other 
#> "#1F77B4" "#AEC7E8" "#FF7F0E" "#FFBB78" "#2CA02C" "#98DF8A" "#D62728" "#FF9896" 

## use custom colors
my_colors <- c("darkorchid4", "deeppink4", "aquamarine3", "darkolivegreen1")
create_cell_colors(
    cell_type = c("A", "B", "C", "D"),
    palette = my_colors,
    preview = TRUE
)
#> Creating custom palette for 4 broad cell types

#>                 A                 B                 C                 D 
#>     "darkorchid4"       "deeppink4"     "aquamarine3" "darkolivegreen1" 

## use Rcolor brewer
create_cell_colors(
    cell_type = c("A", "B", "C"),
    palette = RColorBrewer::brewer.pal(n = 3, name = "Set1"),
    previe = TRUE
)
#> Creating custom palette for 3 broad cell types

#>         A         B         C 
#> "#E41A1C" "#377EB8" "#4DAF4A" 

## 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"),
    palette_name = "classic",
    preview = FALSE
)
#> Creating classic palette for 5 broad cell types
#>       A.1       A.2       B.1         C         D 
#> "#3BB273" "#FF56AF" "#663894" "#F57A00" "#D2B037" 

## 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 = "\\.",
    palette_name = "classic",
    preview = TRUE
)
#> Creating classic palette for 4 broad cell types
#> Creating fine cell type gradients for 2 cell types

#> $broad
#>         A         B         C         D 
#> "#3BB273" "#FF56AF" "#663894" "#F57A00" 
#> 
#> $fine
#>       A.1       A.2       B.1         C         D 
#> "#3BB273" "#9DD8B9" "#FF56AF" "#663894" "#F57A00" 
#> 

## try with custom colors
create_cell_colors(
    cell_types = c("A.1", "A.2", "B.1", "C", "D"),
    split = "\\.",
    palette = my_colors,
    preview = TRUE
)
#> Creating custom palette for 4 broad cell types
#> Creating fine cell type gradients for 2 cell types

#> $broad
#>                 A                 B                 C                 D 
#>     "darkorchid4"       "deeppink4"     "aquamarine3" "darkolivegreen1" 
#> 
#> $fine
#>               A.1               A.2               B.1                 C 
#>         "#68228B"         "#B390C4"         "#8B0A50"     "aquamarine3" 
#>                 D 
#> "darkolivegreen1" 
#>