colorFrom4Vector: Transforms a vector of four values to a set of HSV color...

View source: R/colorFrom4Vector.r

colorFrom4VectorR Documentation

Transforms a vector of four values to a set of HSV color values and their position on a quad plot.

Description

This function converts a vector of four values to HSV color values for plotting. It is useful for showing, for example, the relative probabilities of an individual assigned to four populations.

Usage

colorFrom4Vector(x, cols = c("white", "cyan", "black", "red"))

Arguments

x

Numeric vector with four elements. The values should be proportions or represent proportions (i.e., they will be standardized so they sum to 1).

cols

Four-element vector of characters or integers. Names (or integer codes) of four colors used to convert the value x to HSV color format. The first color corresponds to the condition where the first value of x is >0 and the remainder = 0. The second represents the condition where the second value of x is >0 and the others = 0, and so on.

Value

A list with two named elements: col, an HSV color code translation for the values of x and xy, a two-element numeric vector with the coordinates of x if plotted such that col[1] is at coordinate (0, 0), col[2] at (0, 1), col[3] at (1, 1), and col[4] at (1, 0).

See Also

hsv, col2hsv in the IDPmisc package

Examples

plot(0, xlim=c(0, 1), ylim=c(0, 1), xlab='<--- Population A     Population D --->', ylab='<--- Population A     Population B --->')
for (i in 1:100) {
	x <- runif(4)^5
	out <- colorFrom4Vector(x, cols = c('cyan', 'magenta', 'yellow', 'black'))
	points(out$xy[1], out$xy[2], col=hsv(out$col[1], out$col[2], out$col[3]), pch=16)
}

adamlilith/legendary documentation built on July 28, 2023, 8:13 p.m.