From 7c42358466f2a78b1855e6bc4f2adf2816580368 Mon Sep 17 00:00:00 2001
From: Zuguang Gu <jokergoo@gmail.com>
Date: Wed, 16 Mar 2022 11:05:37 +0100
Subject: [PATCH] convert color strings to hex code

---
 NAMESPACE         | 1 +
 R/utils.R         | 7 ++++++-
 man/colorRamp2.Rd | 3 ++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/NAMESPACE b/NAMESPACE
index 051de43a..9354916d 100755
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -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)
diff --git a/R/utils.R b/R/utils.R
index 92d145c8..185aa6c7 100755
--- a/R/utils.R
+++ b/R/utils.R
@@ -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)) {
@@ -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))
diff --git a/man/colorRamp2.Rd b/man/colorRamp2.Rd
index 6e14b580..c58e7359 100644
--- a/man/colorRamp2.Rd
+++ b/man/colorRamp2.Rd
@@ -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{