Learn R Programming

GSNA (version 0.1.4.2)

makeTwoColorEncodeFunction: makeTwoColorEncodeFunction

Description

Generate a function to take two numerical vector arguments and return a color, either as a vector of hexadecimal encoded colors, or as a three column matrix.

Usage

makeTwoColorEncodeFunction(
  numbers.1,
  numbers.2,
  colors.1 = c("#FFFFFF", "#FF0000"),
  colors.2 = c("#FFFFFF", "#0000FF"),
  combine_method = "mean",
  c1.fun = NULL,
  c2.fun = NULL,
  na.color = "#CCCCCC"
)

Value

makeTwoColorEncodeFunction() returns a function that takes 3 arguments and returns either a vector of hexadecimal colors or a 3-column matrix of columns. The arguments:

numbers.1

A vector of numbers for channel 1, to be encoded as a color value.

numbers.2

A vector of numbers for channel 2, to be encoded as a color value.

output_as

Specifies the type of return value. If 'vector' or 'rgb', the function returns a vector of hexadecimal colors (e.g."#FFCCAA"), if 'matrix','array', a three column numeric matrix is returned (Columns are "R", "G", or "B"). Currently, 'vector' are synonyms 'rgb', as are 'matrix' and 'array'

.

Arguments

numbers.1

A set of numbers to define the range of channel 1 numerical values for which the color encode function will be defined. Only the extreme min and max values are necessary.

numbers.2

A set of numbers to define the range of channel 2 numerical values for which the color encode function will be defined. Only the extreme min and max values are necessary.

colors.1

The range of channel 1 colors to be returned by the function function. (default: c("#FFFFFF", "#FF0000"))

colors.2

The range of channel 2 colors to be returned by the function function. (default: c("#FFFFFF", "#0000FF"))

combine_method

(optional) For dual channel plots this is a string used to indicate how colors are combined to generate a two dimensional color scale. Options are "scaled_geomean" (same as "default"), "standard" (same as "euclidean" ), "negative_euclidean", "mean", and "additive". See details.

c1.fun

(optional) A function to convert the numerical in channel 1 into colors. If not specified, this is generated based on numbers.1 and colors.1.

c2.fun

(optional) A function to convert the numerical in channel 2 into colors. If not specified, this is generated based on numbers.2 and colors.2.

na.color

(optional) The color returned from the function for NA values (default: "#CCCCCC").

Examples

Run this code

# Prepare the function:
twoColorEnc.fun <- makeTwoColorEncodeFunction( numbers.1 = c( 0.4, 6 ),
                                               numbers.2 = c(0.6, 20),
                                               colors.1 = c("white", "red"),
                                               colors.2 = c("white", "green" ),
                                               combine_method = "mean" )
# Encode two vectors of numbers as a single vector of colors:
colors_as_vector <- twoColorEnc.fun( numbers.1 = c( 0.4, 1.2, 5, 6 ),
                                     numbers.2 = c( 0.6, 6, 9, 20 ),
                                     output_as = 'vector' )

Run the code above in your browser using DataLab