You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#' Colour palettes following the March 2018 ECDC guidelines for presentation of surveillance data
2
+
#'
3
+
#' Full document: European Centre for Disease Prevention and Control. Guidelines for presentation of surveillance data.
4
+
#' Stockholm: ECDC; 2018. Available from: \href{https://ecdc.europa.eu/en/publications-data/guidelines-presentation-surveillance-data}{Guidelines for presentation of surveillance data}
5
+
#'
6
+
#' @param col_scale Selected colour scale, defaults to 'green'. Select from 'green', 'blue', 'red', 'grey', 'qual(itative)' or 'hot(cold)'
7
+
#' @param n Number of colours from each colour scale, apart from grey, in order indicated in the guidelines. Defaults to one colour, apart from two colours for the hotcold scale,
8
+
#' max 7-8 colours for each scale. To select grey shades, use the argument grey_shade; to select number of hot (warm) colours in the hotcold scale, use the argument hot_cols.
9
+
#' @param grey_shade Only used with grey colours, defaults to 'medium'. Selected shade(s) of grey in selected order; c('light', 'mediumlight','medium','mediumdark','dark'). Overrides given number of colours (n).
10
+
#' @param hot_cols Selected number of hot (warm) colours in the hotcold colour scale, use only for hotcold. Must be smaller than the total number of colours (n).
11
+
#' Defaults to floored half of total hotcold colours.
stop("Maximum number of colours (n) for selected colour scale is 8!")
72
+
}}
73
73
74
74
if(col_scale=="green"){
75
-
# greens
76
-
opts<- c(rgb(12,72,40, maxColorValue=255),
77
-
rgb(26,110,49, maxColorValue=255),
78
-
rgb(32,119,50, maxColorValue=255),
79
-
rgb(32,129,53, maxColorValue=255),
80
-
rgb(40,147,55, maxColorValue=255),
81
-
rgb(66,158,53, maxColorValue=255),
82
-
rgb(101,179,46, maxColorValue=255),
83
-
rgb(137,190,71, maxColorValue=255),
84
-
rgb(156,198,90, maxColorValue=255),
85
-
rgb(178,207,110, maxColorValue=255),
86
-
rgb(192,212,122, maxColorValue=255),
87
-
rgb(201,217,113, maxColorValue=255),
88
-
rgb(231,231,185, maxColorValue=255))
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))
89
105
}
90
106
91
107
if(col_scale%in%c("blue", "hotcold")){
92
-
# blues
93
-
opts<- c(rgb(0,60,80, maxColorValue=255),
94
-
rgb(26,107,133, maxColorValue=255),
95
-
rgb(39,117,142, maxColorValue=255),
96
-
rgb(60,142,162, maxColorValue=255),
97
-
rgb(73,153,171, maxColorValue=255),
98
-
rgb(95,167,181, maxColorValue=255),
99
-
rgb(124,189,196, maxColorValue=255),
100
-
rgb(147,199,207, maxColorValue=255),
101
-
rgb(165,206,215, maxColorValue=255),
102
-
rgb(173,210,221, maxColorValue=255),
103
-
rgb(187,216,229, maxColorValue=255),
104
-
rgb(194,218,232, maxColorValue=255),
105
-
rgb(227,232,240, maxColorValue=255))
106
-
}
107
-
108
-
if(col_scale%in% c("blue", "green"){
109
-
scale1<-opts[7]
110
-
scale2<-opts[c(4, 11)]
111
-
scale3<-opts[c(2, 7, 12)]
112
-
scale4<-opts[c(2, 5, 9, 12)]
113
-
scale5<-opts[c(1, 4, 10, 13)]
114
-
scale6<-opts[c(1, 3, 6, 8, 11, 13)]
115
-
scale7<-opts[c(1, 2, 5, 7, 9, 12, 13)]
116
-
117
-
cols<- get(paste0("scale", n))
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))}
118
139
}
119
140
120
141
if(col_scale%in%c("red", "hotcold")){
121
-
# reds
122
-
opts<- c(rgb(124,23,15, maxColorValue=255),
123
-
rgb(168,45,23, maxColorValue=255),
124
-
rgb(174,52,23, maxColorValue=255),
125
-
rgb(182,61,23, maxColorValue=255),
126
-
rgb(195,74,23, maxColorValue=255),
127
-
rgb(199,79,27, maxColorValue=255),
128
-
rgb(204,107,33, maxColorValue=255),
129
-
rgb(214,133,43, maxColorValue=255),
130
-
rgb(220,150,53, maxColorValue=255),
131
-
rgb(225,167,68, maxColorValue=255),
132
-
rgb(230,176,77, maxColorValue=255),
133
-
rgb(233,184,85, maxColorValue=255),
134
-
rgb(241,214,118, maxColorValue=255))
135
-
136
-
rscale1<-opts[2]
137
-
rscale2<-opts[c(2, 10)]
138
-
rscale3<-opts[c(2, 7, 12)]
139
-
rscale4<-opts[c(2, 5, 9, 12)]
140
-
rscale5<-opts[c(1, 4, 10, 13)]
141
-
rscale6<-opts[c(1, 3, 6, 8, 11, 13)]
142
-
rscale7<-opts[c(1, 2, 5, 7, 9, 12, 13)]
143
-
if(col_scale=="red"){
144
-
cols<- get(paste0("rscale", n))}
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))}
145
173
}
146
-
147
-
# greyscale
174
+
175
+
# greyscale
148
176
if(col_scale=="grey"){
149
177
if(is.null(grey_shade)){
150
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')")
151
179
grey_shade<-"medium"
152
-
}
180
+
}
153
181
shades<- c("light",
154
-
"mediumlight",
155
-
"medium",
156
-
"mediumdark",
157
-
"dark")
158
-
cols<- c(rgb(229,229,229, maxColorValue=255),
159
-
rgb(199,199,199, maxColorValue=255),
160
-
rgb(128,128,128, maxColorValue=255),
161
-
rgb(113,113,113, maxColorValue=255),
162
-
rgb(63,63,63, maxColorValue=255))
163
-
cols<-cols[shades%in%grey_shade]
164
-
shades<-shades[shades%in%grey_shade]
165
-
cols<-cols[order(match(shades, grey_shade))]
166
-
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
+
167
195
}
168
196
if(col_scale=="qualitative"){
169
-
# qualitative colours
170
-
cols<- c(rgb(101,179,46, maxColorValue=255),
171
-
rgb(124,189,196, maxColorValue=255),
172
-
rgb(192,210,54, maxColorValue=255),
173
-
rgb(62,91,132, maxColorValue=255),
174
-
rgb(0,140,117, maxColorValue=255),
175
-
rgb(130,66,141, maxColorValue=255),
176
-
rgb(232,104,63, maxColorValue=255),
177
-
rgb(184,26,93, maxColorValue=255))
178
-
cols<-cols[1:n]
179
-
}
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
+
}
180
208
if(col_scale=="hotcold"){
181
-
if(n<=hot_cols){
182
-
stop("Total number (n) of colours must be greater than n of hot colours (hot_cols)!")
0 commit comments