我想想象一个十六进制代码颜色的矢量。如果解决方案使用小方框使它们看起来像ggplot2图例那将是很好的:
这些颜色向量可以从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"
如何查看这些矢量代表的颜色?
答案 0 :(得分:4)
grid::grid.raster(RColorBrewer::brewer.pal(9, 'Blues'), interpolate = FALSE)