View source: R/colorFrom4Vector.r
| colorFrom4Vector | R Documentation |
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.
colorFrom4Vector(x, cols = c("white", "cyan", "black", "red"))
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 |
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).
hsv, col2hsv in the IDPmisc package
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.