Last active
August 29, 2015 13:56
-
-
Save derrickturk/8831459 to your computer and use it in GitHub Desktop.
Handy function for HSV-scale-izing real-valued data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hsv.scale <- function (var, hmin, hmax=hmin, smin=1, smax=smin, vmin=1, vmax=vmin, | |
na.col=rgb(0.75, 0.75, 0.75)) | |
{ | |
var.min <- min(var, na.rm=TRUE) | |
var.max <- max(var, na.rm=TRUE) | |
h.f <- approxfun(c(var.min, var.max), c(hmin, hmax)) | |
s.f <- approxfun(c(var.min, var.max), c(smin, smax)) | |
v.f <- approxfun(c(var.min, var.max), c(vmin, vmax)) | |
tmp <- var | |
tmp[is.na(var)] <- var.min | |
col <- hsv(h=h.f(tmp), s=s.f(tmp), v=v.f(tmp)) | |
col[is.na(var)] <- na.col | |
col | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment