Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Created May 17, 2018 13:19
Show Gist options
  • Save matt-dray/657bdc6a63bd83830ef7130c572c310a to your computer and use it in GitHub Desktop.
Save matt-dray/657bdc6a63bd83830ef7130c572c310a to your computer and use it in GitHub Desktop.
Convert RGB to hex for dept colour palette
# Approved colour palette for DfE
# Convert to hex the RGB values provided by the dept
# Matt Dray
# May 2018
# the main need is for plotting stats in publications
# inspiration from https://github.com/ukgovdatascience/govstyle
# this may eventually be added to the dfeR package
# function for converting from RGB to hex
# https://gist.github.com/mbannert/e9fcfa86de3b06068c83
rgb2hex <- function(r,g,b) rgb(r, g, b, maxColorValue = 255)
# create dataframe of RGB and column that converts to hex
dfe_cols <- tibble::tibble(
hue = c(
rep("blue", 5),
rep("red", 5),
rep("orange", 5),
rep("yellow", 5),
rep("green", 5),
rep("purple", 5)
),
lum = rep(1:5, 6), # 1 is darker, 5 is lighter
col_name = paste0("dfe_", hue, "_", lum),
r = c(
16, 64, 112, 159, 207, # blue
138, 161, 185, 208, 232, # red
232, 237, 241, 246, 250, # orange
194, 206, 218, 231, 243, # yellow
0, 51, 102, 153, 207, # green
38, 81, 125, 168, 212 # purple
),
g = c(
79, 114, 149, 185, 220, # b
37, 81, 124, 168, 211, # r
125, 151, 177, 203, 229, # o
162, 181, 199, 218, 236, # y
71, 108, 145, 181, 218, # g
8, 57, 107, 156, 206 # p
),
b = c(
117, 145, 172, 200, 227, # b
41, 84, 127, 169, 212, # r
30, 75, 120, 165, 210, # o
4, 54, 104, 135, 205,# y
18, 65, 113, 160, 189, # g
89, 122, 155, 189, 222 # p
),
hex = rgb2hex(r, g, b)
)
# > print(dfe_cols, n = 30)
# # A tibble: 30 x 7
# hue lum col_name r g b hex
# <chr> <int> <chr> <dbl> <dbl> <dbl> <chr>
# 1 blue 1 dfe_blue_1 16. 79. 117. #104F75
# 2 blue 2 dfe_blue_2 64. 114. 145. #407291
# 3 blue 3 dfe_blue_3 112. 149. 172. #7095AC
# 4 blue 4 dfe_blue_4 159. 185. 200. #9FB9C8
# 5 blue 5 dfe_blue_5 207. 220. 227. #CFDCE3
# 6 red 1 dfe_red_1 138. 37. 41. #8A2529
# 7 red 2 dfe_red_2 161. 81. 84. #A15154
# 8 red 3 dfe_red_3 185. 124. 127. #B97C7F
# 9 red 4 dfe_red_4 208. 168. 169. #D0A8A9
# 10 red 5 dfe_red_5 232. 211. 212. #E8D3D4
# 11 orange 1 dfe_orange_1 232. 125. 30. #E87D1E
# 12 orange 2 dfe_orange_2 237. 151. 75. #ED974B
# 13 orange 3 dfe_orange_3 241. 177. 120. #F1B178
# 14 orange 4 dfe_orange_4 246. 203. 165. #F6CBA5
# 15 orange 5 dfe_orange_5 250. 229. 210. #FAE5D2
# 16 yellow 1 dfe_yellow_1 194. 162. 4. #C2A204
# 17 yellow 2 dfe_yellow_2 206. 181. 54. #CEB536
# 18 yellow 3 dfe_yellow_3 218. 199. 104. #DAC768
# 19 yellow 4 dfe_yellow_4 231. 218. 135. #E7DA87
# 20 yellow 5 dfe_yellow_5 243. 236. 205. #F3ECCD
# 21 green 1 dfe_green_1 0. 71. 18. #004712
# 22 green 2 dfe_green_2 51. 108. 65. #336C41
# 23 green 3 dfe_green_3 102. 145. 113. #669171
# 24 green 4 dfe_green_4 153. 181. 160. #99B5A0
# 25 green 5 dfe_green_5 207. 218. 189. #CFDABD
# 26 purple 1 dfe_purple_1 38. 8. 89. #260859
# 27 purple 2 dfe_purple_2 81. 57. 122. #51397A
# 28 purple 3 dfe_purple_3 125. 107. 155. #7D6B9B
# 29 purple 4 dfe_purple_4 168. 156. 189. #A89CBD
# 30 purple 5 dfe_purple_5 212. 206. 222. #D4CEDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment