[+] Get color palette used to create variable'.color'

hyGet_palette(sp)

hyGet_palette0(sp)

Arguments

sp

A hyperSpec object, that contais variable .color added with function hyAdd_color

Value

Color palette used to create variable .color.

Note

If class of sp is not hyperSpec, function returns NULL.

Author

Vilmantas Gegzna

Examples


data(Spectra2)
Spectra1 <- hyAdd_color(Spectra2, "class")

colnames(Spectra2)
#> [1] "gr"    "class" "spc"  
   #> [1] "gr"    "class" "spc"

colnames(Spectra1)
#> [1] "gr"     "class"  "spc"    ".color"
   #> [1] "gr"     "class"  "spc"    ".color"

# Default label
labels(Spectra1,".color")
#> [1] "Colors for \"class\""
   #>  [1] "Colors for \"class\""

# Names of attributes of variable ".color":
attributes(Spectra1$.color)  %>% names
#> [1] "palette"
  #> [1] "palette"      "variableName"

# Values of attributes:
attributes(Spectra1$.color)
#> $palette
#>    colors labels
#> 1 #E41A1C      K
#> 2 #377EB8      l
#> 3 #4DAF4A      N
#> 4 #984EA3     S1
#> 
  #> $palette
  #> color label
  #> 1 #E41A1C     K
  #> 2 #377EB8     l
  #> 3 #4DAF4A     N
  #> 4 #984EA3    S1
  #>
  #> $variableName
  #> [1] "class"

# Extract color palette:
hyGet_palette(Spectra1)
#> [1] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
   #>  "#377EB8" "#4DAF4A" "#984EA3" "#FF7F00"

   #>      colors   labels
   #>  1 #E41A1C     K
   #>  2 #377EB8     l
   #>  3 #4DAF4A     N
   #>  4 #984EA3    S1

# Extract palette (just colors) as vector:
hyGet_palette0(Spectra1)
#>    colors labels
#> 1 #E41A1C      K
#> 2 #377EB8      l
#> 3 #4DAF4A      N
#> 4 #984EA3     S1
   #>  [1] #E41A1C #377EB8 #4DAF4A #984EA3
   #>  Levels: #377EB8 #4DAF4A #984EA3 #E41A1C

# ATTENTION -------------------------------------------------

# Preserve labels/ color palette (operator ` ]<-`):
Spectra1[1,".color"] <- "red"
hyGet_palette(Spectra1)
#> Warning: Vector `.color` contains more unique colors than listed in the palette. 
#> Newly added colors are: red.
#> [1] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3"
    #>  "#377EB8" "#4DAF4A" "#984EA3" "#FF7F00"

# Overwrite labels/ color palette (operator `$<-`):
# Spectra2a$.color[1] <- "red"
# hyGet_palette(Spectra2a)
    #>  Warning message:
    #>  In hyGet_palette(Spectra2a) : Values of pallete do not exist.
    #>  Most probably they are overwriten by operation `$.color<-`.

labels(Spectra1,".color")
#> [1] "Colors for \"class\""
    #>  ".color"