|
36 | 36 | SurvCols <- function(col_scale = "green", n = NULL, grey_shade = NULL,
|
37 | 37 | hot_cols = NULL){
|
38 | 38 |
|
39 |
| - if(grepl("gray", col_scale)){ |
40 |
| - col_scale <- "grey" |
41 |
| - } |
42 |
| - |
43 |
| - if(grepl("qual", col_scale)){ |
44 |
| - col_scale <- "qualitative" |
45 |
| - } |
46 |
| - |
47 |
| - if(grepl("hot", col_scale)){ |
48 |
| - col_scale <- "hotcold" |
49 |
| - } |
50 |
| - |
51 |
| - if (is.null(n) & col_scale == "hotcold"){ |
52 |
| - n <- 2 |
53 |
| - }else if(is.null(n)){ |
54 |
| - n <- 1 |
55 |
| - }else{ |
56 |
| - n <- n |
57 |
| - } |
58 |
| - |
59 |
| - if(n < 2 & col_scale == "hotcold"){ |
60 |
| - n <- 2 |
61 |
| - } |
62 |
| - |
63 |
| - if(is.null(hot_cols)){ |
64 |
| - hot_cols <- floor(n/2) |
65 |
| - } |
66 |
| - |
67 |
| - if(!is.null(n)){ |
68 |
| - if(n>7 & col_scale != "qualitative"){ |
69 |
| - stop("Maximum number of colours (n) for selected colour scale is 7!") |
70 |
| - }else if(n>8 & col_scale == "qualitative"){ |
71 |
| - stop("Maximum number of colours (n) for selected colour scale is 8!") |
72 |
| - }} |
73 |
| - |
74 |
| - if(col_scale=="green"){ |
75 |
| -# greens |
76 |
| - gscale1 <- rgb(101,179,46, maxColorValue = 255) |
77 |
| - gscale2 <- c(rgb(32,119,50, maxColorValue = 255), |
78 |
| - rgb(178,207,110, maxColorValue = 255)) |
79 |
| - gscale3 <- c(rgb(26,110,49, maxColorValue = 255), |
80 |
| - rgb(101,179,46, maxColorValue = 255), |
81 |
| - rgb(201,217,113, maxColorValue = 255)) |
82 |
| - gscale4 <- c(rgb(26,110,49, maxColorValue = 255), |
83 |
| - rgb(40,147,55, maxColorValue = 255), |
84 |
| - rgb(156,198,90, maxColorValue = 255), |
85 |
| - rgb(201,217,113, maxColorValue = 255)) |
86 |
| - gscale5 <- c(rgb(12,72,40, maxColorValue = 255), |
87 |
| - rgb(32,129,53, maxColorValue = 255), |
88 |
| - rgb(101,179,46, maxColorValue = 255), |
89 |
| - rgb(178,207,110, maxColorValue = 255), |
90 |
| - rgb(231,231,185, maxColorValue = 255)) |
91 |
| - gscale6 <- c(rgb(12,72,40, maxColorValue = 255), |
92 |
| - rgb(32,119,50, maxColorValue = 255), |
93 |
| - rgb(66,158,53, maxColorValue = 255), |
94 |
| - rgb(137,190,71, maxColorValue = 255), |
95 |
| - rgb(192,212,122, maxColorValue = 255), |
96 |
| - rgb(231,231,185, maxColorValue = 255)) |
97 |
| - gscale7 <- c(rgb(12,72,40, maxColorValue = 255), |
98 |
| - rgb(26,110,49, maxColorValue = 255), |
99 |
| - rgb(40,147,55, maxColorValue = 255), |
100 |
| - rgb(101,179,46, maxColorValue = 255), |
101 |
| - rgb(156,198,90, maxColorValue = 255), |
102 |
| - rgb(201,217,113, maxColorValue = 255), |
103 |
| - rgb(231,231,185, maxColorValue = 255)) |
104 |
| - cols <- get(paste0("gscale", n)) |
105 |
| - } |
106 |
| - |
107 |
| - if(col_scale%in%c("blue", "hotcold")){ |
108 |
| -# blues |
109 |
| - bscale1 <- rgb(124,189,196, maxColorValue = 255) |
110 |
| - bscale2 <- c(rgb(60,142,162, maxColorValue = 255), |
111 |
| - rgb(173,210,221, maxColorValue = 255)) |
112 |
| - bscale3 <- c(rgb(26,107,133, maxColorValue = 255), |
113 |
| - rgb(124,189,196, maxColorValue = 255), |
114 |
| - rgb(194,218,232, maxColorValue = 255)) |
115 |
| - bscale4 <- c(rgb(26,107,133, maxColorValue = 255), |
116 |
| - rgb(73,153,171, maxColorValue = 255), |
117 |
| - rgb(165,206,215, maxColorValue = 255), |
118 |
| - rgb(194,218,232, maxColorValue = 255)) |
119 |
| - bscale5 <- c(rgb(0,60,80, maxColorValue = 255), |
120 |
| - rgb(60,142,162, maxColorValue = 255), |
121 |
| - rgb(124,189,196, maxColorValue = 255), |
122 |
| - rgb(173,210,221, maxColorValue = 255), |
123 |
| - rgb(227,232,240, maxColorValue = 255)) |
124 |
| - bscale6 <- c(rgb(0,60,80, maxColorValue = 255), |
125 |
| - rgb(39,117,142, maxColorValue = 255), |
126 |
| - rgb(95,167,181, maxColorValue = 255), |
127 |
| - rgb(147,199,207, maxColorValue = 255), |
128 |
| - rgb(187,216,229, maxColorValue = 255), |
129 |
| - rgb(227,232,240, maxColorValue = 255)) |
130 |
| - bscale7 <- c(rgb(0,60,80, maxColorValue = 255), |
131 |
| - rgb(26,107,133, maxColorValue = 255), |
132 |
| - rgb(73,153,171, maxColorValue = 255), |
133 |
| - rgb(124,189,196, maxColorValue = 255), |
134 |
| - rgb(165,206,215, maxColorValue = 255), |
135 |
| - rgb(194,218,232, maxColorValue = 255), |
136 |
| - rgb(227,232,240, maxColorValue = 255)) |
137 |
| - if(col_scale=="blue"){ |
138 |
| - cols <- get(paste0("bscale", n))} |
139 |
| - } |
140 |
| - |
141 |
| - if(col_scale%in%c("red", "hotcold")){ |
142 |
| -# reds |
143 |
| - rscale1 <- rgb(168,45,23, maxColorValue = 255) |
144 |
| - rscale2 <- c(rgb(168,45,23, maxColorValue = 255), |
145 |
| - rgb(225,167,68, maxColorValue = 255)) |
146 |
| - rscale3 <- c(rgb(168,45,23, maxColorValue = 255), |
147 |
| - rgb(204,107,33, maxColorValue = 255), |
148 |
| - rgb(233,184,85, maxColorValue = 255)) |
149 |
| - rscale4 <- c(rgb(168,45,23, maxColorValue = 255), |
150 |
| - rgb(195,74,23, maxColorValue = 255), |
151 |
| - rgb(220,150,53, maxColorValue = 255), |
152 |
| - rgb(233,184,85, maxColorValue = 255)) |
153 |
| - rscale5 <- c(rgb(124,23,15, maxColorValue = 255), |
154 |
| - rgb(182,61,23, maxColorValue = 255), |
155 |
| - rgb(204,107,33, maxColorValue = 255), |
156 |
| - rgb(225,167,68, maxColorValue = 255), |
157 |
| - rgb(241,214,118, maxColorValue = 255)) |
158 |
| - rscale6 <- c(rgb(124,23,15, maxColorValue = 255), |
159 |
| - rgb(174,52,23, maxColorValue = 255), |
160 |
| - rgb(199,79,27, maxColorValue = 255), |
161 |
| - rgb(214,133,43, maxColorValue = 255), |
162 |
| - rgb(230,176,77, maxColorValue = 255), |
163 |
| - rgb(241,214,118, maxColorValue = 255)) |
164 |
| - rscale7 <- c(rgb(124,23,15, maxColorValue = 255), |
165 |
| - rgb(168,45,23, maxColorValue = 255), |
166 |
| - rgb(195,74,23, maxColorValue = 255), |
167 |
| - rgb(204,107,33, maxColorValue = 255), |
168 |
| - rgb(220,150,53, maxColorValue = 255), |
169 |
| - rgb(233,184,85, maxColorValue = 255), |
170 |
| - rgb(241,214,118, maxColorValue = 255)) |
171 |
| - if(col_scale=="red"){ |
172 |
| - cols <- get(paste0("rscale", n))} |
173 |
| - } |
174 |
| - |
175 |
| -# greyscale |
176 |
| - if(col_scale == "grey"){ |
177 |
| - if(is.null(grey_shade)){ |
178 |
| - message("Greyzone - number of colours defined by shades of grey, defaults to 'medium'. If you want specific grey shade(s) in specific order, please insert the grey_shade(s): c('light', 'mediumlight','medium','mediumdark','dark')") |
179 |
| - grey_shade <- "medium" |
180 |
| - } |
181 |
| - shades <- c("light", |
182 |
| - "mediumlight", |
183 |
| - "medium", |
184 |
| - "mediumdark", |
185 |
| - "dark") |
186 |
| - cols <- c(rgb(229,229,229, maxColorValue = 255), |
187 |
| - rgb(199,199,199, maxColorValue = 255), |
188 |
| - rgb(128,128,128, maxColorValue = 255), |
189 |
| - rgb(113,113,113, maxColorValue = 255), |
190 |
| - rgb(63,63,63, maxColorValue = 255)) |
191 |
| - cols <- cols[shades %in% grey_shade] |
192 |
| - shades <- shades[shades %in% grey_shade] |
193 |
| - cols <- cols[order(match(shades, grey_shade))] |
194 |
| - |
195 |
| - } |
196 |
| - if(col_scale=="qualitative"){ |
197 |
| -# qualitative colours |
198 |
| - cols <- c(rgb(101,179,46, maxColorValue = 255), |
199 |
| - rgb(124,189,196, maxColorValue = 255), |
200 |
| - rgb(192,210,54, maxColorValue = 255), |
201 |
| - rgb(62,91,132, maxColorValue = 255), |
202 |
| - rgb(0,140,117, maxColorValue = 255), |
203 |
| - rgb(130,66,141, maxColorValue = 255), |
204 |
| - rgb(232,104,63, maxColorValue = 255), |
205 |
| - rgb(184,26,93, maxColorValue = 255)) |
206 |
| - cols <- cols[1:n] |
207 |
| -} |
208 |
| - if(col_scale=="hotcold"){ |
209 |
| - if(n<=hot_cols){ |
210 |
| - stop("Total number (n) of colours must be greater than n of hot colours (hot_cols)!") |
211 |
| - } |
212 |
| - cold_cols <- n-hot_cols |
213 |
| - cols <- get(paste0("rscale", hot_cols)) |
214 |
| - cols <- c(cols, rev(get(paste0("bscale", cold_cols)))) |
215 |
| - |
216 |
| -} |
217 |
| - |
218 |
| - if(!col_scale%in%c("green", "blue", "red", "grey", "qualitative", "hotcold")){ |
219 |
| - stop("col_scale is not among the currently defined colour palettes, |
220 |
| - please select from 'green', 'blue', 'red', 'grey', 'qual(itative)' or 'hot(cold)'") |
221 |
| -} |
222 |
| - return(cols) |
| 39 | + return(SurvColors(col_scale = col_scale, n = n, grey_shade = grey_shade, |
| 40 | + hot_cols = hot_cols)) |
223 | 41 | }
|
0 commit comments