
Generate a named color vector from a variable
SelectColors.RdAccepts any vector (factor or not), resolves its levels, and returns a named
character vector of colors - one per level - ready to pass to
scale_color_manual(), PrepObject(custom_colors = ...), or any
scSidekick colors argument.
Arguments
- x
A vector (factor, character, or numeric).
- palette
Color source. One of:
A Nour_pal name string (e.g.
"all","spectrum").A character vector of hex colors - interpolated to the required length via
colorRampPalette.A palette function that accepts an integer
nand returnsncolors (e.g.scales::hue_pal()).
Default
"all".- levels
Optional character vector specifying level order. Levels present in
xbut absent here are appended at the end.- reverse
Logical. Reverse the color order. Default
FALSE.
Details
If x is not already a factor it is converted automatically and a
message is printed. Supply levels to control the order; any levels
present in the data but not listed are appended at the end.
Examples
if (FALSE) { # \dontrun{
# From a Seurat metadata column
cols <- SelectColors(SeuratObj$seurat_clusters)
# Custom level order + warm palette
cols <- SelectColors(SeuratObj$Group,
levels = c("Control", "Treated"),
palette = "warm")
# Any color vector as palette
cols <- SelectColors(SeuratObj$CellType,
palette = c("#003f5c", "#bc5090", "#ffa600"))
} # }