Skip to content

Commit

Permalink
convert color strings to hex code
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Mar 16, 2022
1 parent 533ba37 commit 7c42358
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ importFrom("colorspace", hex2RGB)
importFrom("colorspace", sRGB)
importFrom("grDevices", "dev.cur", "dev.prev", "dev.set")
importFrom("grDevices", "dev.off", "pdf")
importFrom("grDevices", "hcl.colors")
importFrom("grDevices", as.raster)
importFrom("grDevices", col2rgb)
importFrom("grDevices", rgb)
Expand Down
7 changes: 6 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ as.degree = function(radian) {
# == example
# col_fun = colorRamp2(c(-1, 0, 1), c("green", "white", "red"))
# col_fun(c(-2, -1, -0.5, 0, 0.5, 1, 2))
colorRamp2 = function(breaks, colors, transparency = 0, space = "LAB", hcl_palette = NULL, reverse = FALSE) {
colorRamp2 = function(breaks, colors, transparency = 0, space = "LAB",
hcl_palette = NULL, reverse = FALSE) {

breaks_o = breaks
if(!is.null(hcl_palette)) {
Expand Down Expand Up @@ -599,6 +600,10 @@ col2value = function(r, g, b, col_fun) {

n = length(r)

if(inherits(colors, "character")) {
colors = col2rgb(colors)
}

## convert all colors to the specified space
m = coords(as(sRGB(r, g, b), space))
breaks_m = coords(as(sRGB(colors), space))
Expand Down
3 changes: 2 additions & 1 deletion man/colorRamp2.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Color interpolation
Color interpolation
}
\usage{
colorRamp2(breaks, colors, transparency = 0, space = "LAB", hcl_palette = NULL, reverse = FALSE)
colorRamp2(breaks, colors, transparency = 0, space = "LAB",
hcl_palette = NULL, reverse = FALSE)
}
\arguments{

Expand Down

0 comments on commit 7c42358

Please sign in to comment.