Is there a way to create a sequence over colors in R?
for example, anything like:
seq("#000000", "#999999", length=20)
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.
ROYGBIV is an acronym for the sequence of hues commonly described as making up a rainbow: red, orange, yellow, green, blue, indigo, and violet.
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()
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)
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")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With