comparison viridis.R @ 3:546c7ccd2ed4 draft default tip

"planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit 911f4beba3dcb25c1033e8239426f8f763683523"
author workflow4metabolomics
date Fri, 04 Feb 2022 09:01:11 +0000
parents dff7bde22102
children
comparison
equal deleted inserted replaced
2:dff7bde22102 3:546c7ccd2ed4
1 viridis <- function (n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D") 1 viridis <- function(n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D") {
2 {
3 if (begin < 0 | begin > 1 | end < 0 | end > 1) { 2 if (begin < 0 | begin > 1 | end < 0 | end > 1) {
4 stop("begin and end must be in [0,1]") 3 stop("begin and end must be in [0,1]")
5 } 4 }
6 if (abs(direction) != 1) { 5 if (abs(direction) != 1) {
7 stop("direction must be 1 or -1") 6 stop("direction must be 1 or -1")
9 if (direction == -1) { 8 if (direction == -1) {
10 tmp <- begin 9 tmp <- begin
11 begin <- end 10 begin <- end
12 end <- tmp 11 end <- tmp
13 } 12 }
14 option <- switch(EXPR = option, A = "A", magma = "A", 13 option <- switch(EXPR = option, A = "A", magma = "A",
15 B = "B", inferno = "B", C = "C", plasma = "C", 14 B = "B", inferno = "B", C = "C", plasma = "C",
16 D = "D", viridis = "D", E = "E", cividis = "E", 15 D = "D", viridis = "D", E = "E", cividis = "E", {
17 {
18 warning(paste0("Option '", option, "' does not exist. Defaulting to 'viridis'.")) 16 warning(paste0("Option '", option, "' does not exist. Defaulting to 'viridis'."))
19 "D" 17 "D"
20 }) 18 })
21 map <- viridisLite::viridis.map[viridisLite::viridis.map$opt == 19 map <- viridisLite::viridis.map[viridisLite::viridis.map$opt ==
22 option, ] 20 option, ]
23 map_cols <- grDevices::rgb(map$R, map$G, map$B) 21 map_cols <- grDevices::rgb(map$R, map$G, map$B)
24 fn_cols <- grDevices::colorRamp(map_cols, space = "Lab", 22 fn_cols <- grDevices::colorRamp(map_cols, space = "Lab",
25 interpolate = "spline") 23 interpolate = "spline")
26 cols <- fn_cols(seq(begin, end, length.out = n))/255 24 cols <- fn_cols(seq(begin, end, length.out = n)) / 255
27 grDevices::rgb(cols[, 1], cols[, 2], cols[, 3], alpha = alpha) 25 grDevices::rgb(cols[, 1], cols[, 2], cols[, 3], alpha = alpha)
28 } 26 }