如何绘制十六进制代码颜色的矢量

时间:2021-01-23 00:10:08

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:

我想想象一个十六进制代码颜色的矢量。如果解决方案使用小方框使它们看起来像ggplot2图例那将是很好的:

如何绘制十六进制代码颜色的矢量

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

这些颜色矢量可以从RColorBrewer包中获得,也可以使用默认的ggplot2色调生成:

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?

我怎样才能看到这些矢量代表什么颜色?

1 个解决方案

#1


3  

grid::grid.raster(RColorBrewer::brewer.pal(9, 'Blues'), interpolate = FALSE)

#1


3  

grid::grid.raster(RColorBrewer::brewer.pal(9, 'Blues'), interpolate = FALSE)