The package can be installed from CRAN:
install.packages("colorRamp2")
or directly from GitHub:
::install_github("jokergoo/colorRamp2") devtools
The colorRamp2()
function can generate a color mapping
function from a vector of break values and a vector of corresponding
colors. Other colors are linearly interpolated in a certain color
space.
library(colorRamp2)
= colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))
col_fun col_fun(seq(0, 1, length = 20))
## [1] "#0000FFFF" "#522CFFFF" "#7448FFFF" "#8E61FFFF" "#A479FFFF" "#B891FFFF"
## [7] "#C9A9FFFF" "#DAC1FFFF" "#E9DAFFFF" "#F8F3FFFF" "#FFF5F1FF" "#FFE1D6FF"
## [13] "#FFCDBBFF" "#FFB8A1FF" "#FFA388FF" "#FF8E6EFF" "#FF7756FF" "#FF5E3DFF"
## [19] "#FF3F23FF" "#FF0000FF"
plot(NULL, xlim = c(0, 1), ylim = c(0, 1))
= seq(0, 1, length = 20)
x = rep(0.5, 20)
y points(x, y, pch = 16, col = col_fun(x), cex = 2)
MIT @ Zuguang Gu