library(mtb)
The section of colors are flexible and convenient using functions like grDevices::colorRamp()
, or grDevices::rainbow()
. There are situations that we need to reserve some colors for some specific groups, and control the mapping of color and group values. color_set_palette()
generate a list of color by taking group values and allows two reserved colors. color_test_palette()
shows selected palette on two different formats (bar or line) to visually inspect the color selection.
This is a basic example which shows you how to automatically select colors for each of the categories, a to g, by setting 3 major colors. The second argument specify the order of ‘a’ to ‘g’. The third and fourth arguments specify that ‘a’ is assigned to the black color, and ‘b’ is assigned to the gray color.
library(mtb)
= color_set_palette(c('a','b','d','c','e','f','g'), c(1,2,4,3,5,6,7),black='a',gray9='b',cols=c('blue', 'cyan','orange')) colvect
This is a basic example which shows you how to quickly test selected colors:
color_test_palette(colvect, type='bar')
color_test_palette(colvect, type='line')
Below is an example that uses grDevices::rainbow()
function to generate a color vector to be used as major colors. Note that if the order of group is set as NULL, the order will be given by the alphabetical order of group values.
=paste('g', sample(1:12,120, replace=T), sep="")
group= color_set_palette(group, NULL, black='g1',gray9='g2',cols=rainbow(5))
colvect #> Warning in color_set_palette(group, NULL, black = "g1", gray9 = "g2", cols =
#> rainbow(5)): invalid vectn
This is a basic example which shows you how to quickly test selected colors:
color_test_palette(colvect, type='bar')
color_test_palette(colvect, type='line')