Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 725
Ricardo Saporta Avatar asked Feb 21 '13 19:02

Ricardo Saporta


People also ask

How do I list colors in R?

In R, colors can be specified either by name (e.g col = “red”) or as a hexadecimal RGB triplet (such as col = “#FFCC00”). You can also use other color systems such as ones taken from the RColorBrewer package.

What is color sequence?

ROYGBIV is an acronym for the sequence of hues commonly described as making up a rainbow: red, orange, yellow, green, blue, indigo, and violet.

What is color palette in R?

In its simplest form, a palette in R is simply a vector of colors. This vector can be include the hex triplet or R color names. The default palette can be seen through palette(): > palette("default") # you'll only need this line if you've previously changed the palette from the default. > palette()


1 Answers

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").

like image 121
Josh O'Brien Avatar answered Nov 04 '22 23:11

Josh O'Brien