-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RGB for raster #2
Comments
@ozjimbob if you want to try this out My todo list:
|
Working on pulling out the logic, not sure whether to return a vector of hex colours, or an array of rgb like #' @param x numeric values
#' @param col function to generate colours, or a vector of hex colours
#' @param ... ignored
#' @param breaks optionally used to specify color mapping
#' @param n optionally used to specify density of colours from `col` (ignored if breaks is set)
#' @name cv_rgb
#' @export
cv_rgb <- function(x, col, ..., breaks = NULL, n = NULL) {
if (missing(col)) {
## just not sure how to use hcl.colors to get a function, so ...
col <- colorRampPalette(hcl.colors(12, "YlOrRd", rev = TRUE))
}
if (!is.null(breaks)) n <- length(breaks) - 1L
if (is.function(col)) {
if (is.null(n)) {
n <- 24
}
col <- col(n)
}
## scales::rescale(x)
scl <- function(x) (x - min(x,na.rm= TRUE))/diff(range(x, na.rm = TRUE))
if (!is.null(breaks)) {
col <- colorRampPalette(col)(length(breaks) - 1)
outcols <- col[cut(x, breaks)]
} else {
outcols <- col[scl(x) * (length(col) - 1) + 1]
}
outcols
} |
All done in #3 Seems quite clear now, with rename of functions and the role of |
where to put this
The text was updated successfully, but these errors were encountered: