2

I would like to visualise a vector of hex code colours. It would be nice if the solution uses tiny square boxes so that they look like a ggplot2 legend:

enter image description here

These colour vectors are obtained either from the RColorBrewer package or are generated using the default ggplot2 hue:

get_gg_color_hue <- function(n) {
  hues = seq(15, 375, length = n + 1)
  hcl(h = hues, l = 65, c = 100)[1:n]
}

E.g.:

> RColorBrewer::brewer.pal(9, 'Blues')
[1] "#F7FBFF" "#DEEBF7" "#C6DBEF" "#9ECAE1" "#6BAED6" "#4292C6" "#2171B5" "#08519C" "#08306B"

And

> get_gg_color_hue(9)
[1] "#F8766D" "#D39200" "#93AA00" "#00BA38" "#00C19F" "#00B9E3" "#619CFF" "#DB72FB" "#FF61C3"

How can I see what colours each of these vectors represent?

Community
  • 1
  • 1
Alex
  • 15,186
  • 15
  • 73
  • 127

1 Answers1

5
grid::grid.raster(RColorBrewer::brewer.pal(9, 'Blues'), interpolate = FALSE)
baptiste
  • 75,767
  • 19
  • 198
  • 294