Skip to contents

Color ramp for bivariate colors, using x- and y-axis input values to apply colors.

Usage

colorRamp2D(
  column_breaks = c(-2, -1, 0, 1, 2),
  row_breaks = c(0, 5, 10),
  mcolor = NULL,
  na_color = "grey15",
  return_rgb = FALSE,
  transparency = 0,
  space = "sRGB",
  verbose = FALSE,
  ...
)

Arguments

column_breaks

numeric vector of column breaks.

row_breaks

numeric vector of row breaks.

mcolor

character matrix of R colors, with dimensions equal to the number of column_breaks and row_breaks.

na_color

character color used for NA values.

return_rgb

logical default FALSE, whether the color function should return RGB color format, or character hex colors.

transparency

numeric default 0, passed to circlize::colorRamp2().

space

character string with color space, default 'sRGB'.

verbose

logical whether to print verbose output.

...

additional arguments are ignored.

Value

function that takes input with arguments:

  • x: numeric x-axis value. It only accepts one value.

  • return_rgb: logical whether to return RGB color

  • max_value: maximum value, ignored

  • y: numeric y-axis value. It only accepts one value.

  • ...: additional arguments are ignored

Details

This function is intentionally similar to circlize::colorRamp2(), in that it defines a specific color to a specific numeric value. In this case, it uses two numeric input values, intended to be x- and y-axis values, columns and rows, respectively.

The default condition it to use divergent colors as x-axis (columns), and a white-to-dark gradient as y-axis (rows). In this way the y-axis represents P-value significance, and x-axis represents direction, with -2 (down), 0 (no direction), and +2 (up).

This function is not intended to be particularly user-friendly, it simply takes column_breaks, row_breaks, and a matrix of colors, and returns a color function that generates one color for each x,y value provided.

Examples

mcolor <- cbind(
   jamba::getColorRamp("Reds", n=3, trimRamp=c(0, 2)),
   jamba::getColorRamp("Oranges", n=3, trimRamp=c(0, 3)),
   jamba::getColorRamp("gold", n=3, trimRamp=c(0, 3)),
   jamba::getColorRamp("Greens", n=3, trimRamp=c(0, 3)),
   jamba::getColorRamp("Blues", n=3, trimRamp=c(0, 2))
)
row_breaks <- c(0, 0.5, 1);
column_breaks <- c(-2, -1, 0, 1, 2);
rownames(mcolor) <- row_breaks;
colnames(mcolor) <- column_breaks;
jamba::imageByColors(mcolor);
title(
   cex.main=1.5,
   cex.lab=1.5,
   main="Bivariate color scale",
   xlab="Directionality",
   ylab="Score");


col_fun <- colorRamp2D(
   column_breaks=column_breaks,
   row_breaks=row_breaks,
   mcolor=mcolor)
display_colorRamp2D(col_fun, pretty.n=c(8, 5));

display_colorRamp2D(col_fun, pretty.n=NULL);


mcolor1 <- matrix(ncol=3,
   c("white", "red",
      "white", "gold",
      "white", "blue3"));
row_breaks1 <- c(0, 1);
column_breaks1 <- c(-1, 0, 1);
rownames(mcolor1) <- row_breaks1;
colnames(mcolor1) <- column_breaks1;
jamba::imageByColors(mcolor1);


col_fun1 <- colorRamp2D(column_breaks=column_breaks1,
   row_breaks=row_breaks1,
   space="LUV",
   mcolor=mcolor1)
display_colorRamp2D(col_fun1);