Retrieve Custom Color Palettes for Data Visualization
Source:R/mStat_get_palette.R
mStat_get_palette.Rd
This function provides a selection of color palettes inspired by various scientific publications, particularly the `ggsci` package, which offers a wide range of color palettes used in scientific journals and publications. It allows users to choose a predefined palette from `ggsci` or specify their own set of colors.
Value
A vector of color codes. If a predefined palette name is provided, the corresponding palette from the `ggsci` package is returned. If a vector of color codes is provided, it is returned as-is. If the input is NULL or an unrecognized string, a default palette is returned.
Examples
# Default palette
mStat_get_palette()
#> [1] "#E31A1C" "#1F78B4" "#FB9A99" "#33A02C" "#FDBF6F" "#B2DF8A" "#A6CEE3"
#> [8] "#BA7A70" "#9D4E3F" "#829BAB"
# Predefined palette from `ggsci`: 'nejm'
mStat_get_palette("nejm")
#> [1] "#BC3C29" "#0072B5" "#E18727" "#20854E" "#7876B1" "#6F99AD" "#FFDC91"
#> [8] "#EE4C97"
# Other predefined palettes
# 'npg' palette
mStat_get_palette("npg")
#> [1] "#E64B35" "#4DBBD5" "#00A087" "#3C5488" "#F39B7F" "#8491B4" "#91D1C2"
#> [8] "#DC0000" "#7E6148" "#B09C85"
# 'aaas' palette
mStat_get_palette("aaas")
#> [1] "#3B4992" "#EE0000" "#008B45" "#631879" "#008280" "#BB0021" "#5F559B"
#> [8] "#A20056" "#808180" "#1B1919"
# 'lancet' palette
mStat_get_palette("lancet")
#> [1] "#00468B" "#ED0000" "#42B540" "#0099B4" "#925E9F" "#FDAF91" "#AD002A"
#> [8] "#ADB6B6" "#1B1919"
# 'jama' palette
mStat_get_palette("jama")
#> [1] "#374E55" "#DF8F44" "#00A1D5" "#B24745" "#79AF97" "#6A6599" "#80796B"
# 'jco' palette
mStat_get_palette("jco")
#> [1] "#0073C2" "#EFC000" "#868686" "#CD534C" "#7AA6DC" "#003C67" "#8F7700"
#> [8] "#3B3B3B" "#A73030" "#4A6990"
# 'ucscgb' palette
mStat_get_palette("ucscgb")
#> [1] "#FF0000" "#FF9900" "#FFCC00" "#00FF00" "#6699FF" "#CC33FF" "#99991E"
#> [8] "#999999" "#FF00CC" "#CC0000" "#FFCCCC" "#FFFF00" "#CCFF00" "#358000"
#> [15] "#0000CC" "#99CCFF" "#00FFFF" "#CCFFFF" "#9900CC" "#CC99FF" "#996600"
#> [22] "#666600" "#666666" "#CCCCCC" "#79CC3D" "#CCCC99"
# Custom color vector
mStat_get_palette(c("#123456", "#654321"))
#> [1] "#123456" "#654321"
# Unrecognized input returns default palette
mStat_get_palette("unknown")
#> [1] "#E31A1C" "#1F78B4" "#FB9A99" "#33A02C" "#FDBF6F" "#B2DF8A" "#A6CEE3"
#> [8] "#BA7A70" "#9D4E3F" "#829BAB"
# Using a longer custom color vector
mStat_get_palette(c("#FF5733", "#33FF57", "#3357FF", "#FF33FF"))
#> [1] "#FF5733" "#33FF57" "#3357FF" "#FF33FF"
# Using an empty string (should return default palette)
mStat_get_palette("")
#> [1] "#E31A1C" "#1F78B4" "#FB9A99" "#33A02C" "#FDBF6F" "#B2DF8A" "#A6CEE3"
#> [8] "#BA7A70" "#9D4E3F" "#829BAB"
# Using a single color code (treated as custom vector)
mStat_get_palette("#FF5733")
#> [1] "#E31A1C" "#1F78B4" "#FB9A99" "#33A02C" "#FDBF6F" "#B2DF8A" "#A6CEE3"
#> [8] "#BA7A70" "#9D4E3F" "#829BAB"