Mercurial > repos > marie-tremblay-metatoul > 2dnmrannotation
comparison viridis.R @ 4:cf11fa0c47c8 draft default tip
planemo upload for repository https://github.com/workflow4metabolomics/tools-metabolomics commit b5f7f56b5ffc3c900236c077f72b321df20647be
author | workflow4metabolomics |
---|---|
date | Thu, 23 Jan 2025 15:28:44 +0000 |
parents | 546c7ccd2ed4 |
children |
comparison
equal
deleted
inserted
replaced
3:546c7ccd2ed4 | 4:cf11fa0c47c8 |
---|---|
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 if (begin < 0 | begin > 1 | end < 0 | end > 1) { | 2 if (begin < 0 | begin > 1 | end < 0 | end > 1) { |
3 stop("begin and end must be in [0,1]") | 3 stop("begin and end must be in [0,1]") |
4 } | 4 } |
5 if (abs(direction) != 1) { | 5 if (abs(direction) != 1) { |
6 stop("direction must be 1 or -1") | 6 stop("direction must be 1 or -1") |
7 } | 7 } |
8 if (direction == -1) { | 8 if (direction == -1) { |
9 tmp <- begin | 9 tmp <- begin |
10 begin <- end | 10 begin <- end |
11 end <- tmp | 11 end <- tmp |
12 } | 12 } |
13 option <- switch(EXPR = option, A = "A", magma = "A", | 13 option <- switch(EXPR = option, |
14 B = "B", inferno = "B", C = "C", plasma = "C", | 14 A = "A", |
15 D = "D", viridis = "D", E = "E", cividis = "E", { | 15 magma = "A", |
16 warning(paste0("Option '", option, "' does not exist. Defaulting to 'viridis'.")) | 16 B = "B", |
17 "D" | 17 inferno = "B", |
18 }) | 18 C = "C", |
19 map <- viridisLite::viridis.map[viridisLite::viridis.map$opt == | 19 plasma = "C", |
20 option, ] | 20 D = "D", |
21 map_cols <- grDevices::rgb(map$R, map$G, map$B) | 21 viridis = "D", |
22 fn_cols <- grDevices::colorRamp(map_cols, space = "Lab", | 22 E = "E", |
23 interpolate = "spline") | 23 cividis = "E", |
24 cols <- fn_cols(seq(begin, end, length.out = n)) / 255 | 24 { |
25 grDevices::rgb(cols[, 1], cols[, 2], cols[, 3], alpha = alpha) | 25 warning(paste0("Option '", option, "' does not exist. Defaulting to 'viridis'.")) |
26 "D" | |
27 } | |
28 ) | |
29 map <- viridisLite::viridis.map[viridisLite::viridis.map$opt == | |
30 option, ] | |
31 map_cols <- grDevices::rgb(map$R, map$G, map$B) | |
32 fn_cols <- grDevices::colorRamp(map_cols, | |
33 space = "Lab", | |
34 interpolate = "spline" | |
35 ) | |
36 cols <- fn_cols(seq(begin, end, length.out = n)) / 255 | |
37 grDevices::rgb(cols[, 1], cols[, 2], cols[, 3], alpha = alpha) | |
26 } | 38 } |