RColorBrewer允许您获得少量视觉上令人愉悦的颜色,如下所示:
> library(RColorBrewer)
> brewer.pal(11, "Spectral")
[1] "#9E0142" "#D53E4F" "#F46D43" "#FDAE61" "#FEE08B" "#FFFFBF" "#E6F598"
[8] "#ABDDA4" "#66C2A5" "#3288BD" "#5E4FA2"
但如果你要求的金额超过这个金额,他们只会给你相同的最高金额:
> brewer.pal(12, "Spectral")
[1] "#9E0142" "#D53E4F" "#F46D43" "#FDAE61" "#FEE08B" "#FFFFBF" "#E6F598"
[8] "#ABDDA4" "#66C2A5" "#3288BD" "#5E4FA2"
Warning message:
In brewer.pal(12, "Spectral") :
n too large, allowed maximum for palette Spectral is 11
Returning the palette you asked for with that many colors
如果提供更大的数字,是否可以输出更多的颜色(可能通过在最远的颜色之间进行插值)?
答案 0 :(得分:1)
执行此操作的标准方法是使用插入一组给定颜色的函数。然后它创建一个新的调色板。在这种情况下colorRampPalette
:
require(RColorBrewer)
colorRampPalette( brewer.pal(9,"YlOrRd") )(50)
# [1] "#FFFFCC" "#FFFCC4" "#FFF9BD" "#FFF6B6" "#FFF3AF" "#FFF0A8" "#FFEDA0"
# [8] "#FEEA9A" "#FEE693" "#FEE38C" "#FEE085" "#FEDD7E" "#FED977" "#FED470"
#[15] "#FECD6A" "#FEC763" "#FEC15C" "#FEBA55" "#FEB44E" "#FDAE4A" "#FDA847"
#[22] "#FDA245" "#FD9C42" "#FD963F" "#FD903D" "#FC873A" "#FC7D37" "#FC7334"
#[29] "#FC6931" "#FC5E2E" "#FC542B" "#FA4A29" "#F64226" "#F23924" "#EE3122"
#[36] "#EA2820" "#E6201D" "#E1181C" "#DB141E" "#D5101F" "#CE0C21" "#C80722"
#[43] "#C20324" "#BB0026" "#B10026" "#A70026" "#9D0026" "#930026" "#890026"
#[50] "#800026"
另见@rawr 在评论中的回答。在此处添加所需的输出,以便更好地了解该函数的作用。