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

时间:2017-01-03 04:05:38

标签: r ggplot2 colors

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

enter image description here

这些颜色向量可以从RColorBrewer包获得,也可以使用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"

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

如何查看这些矢量代表的颜色?

1 个答案:

答案 0 :(得分:4)

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