Learn R Programming

GSNA (version 0.1.4.2)

makeOneColorEncodeFunction: makeOneColorEncodeFunction

Description

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

Usage

makeOneColorEncodeFunction(
  numbers,
  colors = c("#FFFFFF", "#FFFF00", "#FF0000"),
  c.fun = NULL,
  na.color = "#CCCCCC"
)

Value

The function 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

A vector of numbers to be encoded as a color value.

numbers.2

This argument is ignored, and is only included to be compatible with functions generated by the 2-color encoding functions that take three arguments.

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

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

colors

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

c.fun

(optional) A function to convert numerical values into colors. If not specified, this is generated based on numbers and colors using makeLinearNColorGradientFunction().

na.color

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

Examples

Run this code

# Prepare the function:
oneColorEnc.fun <- makeOneColorEncodeFunction( numbers = c( 0.4, 6 ),
                                               colors = c("white", "yellow", "red"),
                                             )

# Encode a vector of numbers as a vector of colors:
colors_as_vector <- oneColorEnc.fun( numbers = c( 0.4, 1.2, 5, 6 ),
                                     output_as = 'vector' )

Run the code above in your browser using DataLab