Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating different shades of the same colour in R

I want to generate different shades of a colour going from lighter tone to darker tone

colfunc <- colorRampPalette(c("green", "red"))
colfunc(10)

plot(rep(1,10),col=colfunc(10),pch=19,cex=3)

enter image description here

If I try to run this for a single colour

 colfunc <- colorRampPalette("green")
 colfunc(10)
 [1] "#00FF00" "#00FF00" "#00FF00" "#00FF00" "#00FF00" "#00FF00"
 [7] "#00FF00" "#00FF00" "#00FF00" "#00FF00"

It returns me the same values. How can I generate different shades of a single colour say going from light green to darker green?

like image 920
89_Simple Avatar asked Jun 21 '18 14:06

89_Simple


People also ask

How do you make different colors of shades?

Tints and shades are art terminology for the lighter and darker variations of a single color. They're created by adding white (for tints) or black (for shades) to a base color.

How do you set a color 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.

How do I use hex color in R?

To see a list of the named colors (just the names, not the colors themselves) use the command colors(). R uses hexadecimal colors. These are represented as strings of six characters. Red, green, and blue components are specified as two hexadecimal digits (0–9, A–F), in the form #rrggbb.


1 Answers

fc <- colorRampPalette(c("green", "darkgreen"))
plot(rep(1, 10),col = fc(10), pch = 19, cex = 3)

Is it what you need?

clrs

like image 71
utubun Avatar answered Sep 28 '22 12:09

utubun