Search code examples
rcolorscolor-pickercolor-palette

sequence over colors in R


Is there a way to create a sequence over colors in R?

for example, anything like:

 seq("#000000", "#999999", length=20)

Solution

  • See colorRampPalette and the related colorRamp function.

    palette <- colorRampPalette(colors=c("#000000", "#FFFFFF"))
    cols <- palette(20)
    plot(1:20, col=cols, pch=16, cex=3)
    

    enter image description here

    For some other interesting options, check out the colorspace package, loading it and then doing example(rainbow_hcl) and then, if you're intrigued by what you see, vignette("hcl-colors").