duttashi / visualizer

My experiments in data visualizations. Feel free to show your :heart: by giving a star :star:
MIT License
15 stars 1 forks source link

How to convert colors to pastel colors? #53

Open duttashi opened 6 years ago

duttashi commented 6 years ago

This question was originally asked on SO. I'm reproducing it here for future reference. Pastel colors have the property of high value and low saturation in the HSV color space. The colors of this family are usually described as soothing,soft, near neutral, milky, washed out, desaturated, and lacking strong chromatic content.

duttashi commented 6 years ago

A possible solution;

a <-c("red","red1","red2","red3","grey","darkgreen","skyblue","blue","magenta","magenta4","yellow","orange","pink","pink","black")
par(mfrow=c(3,1))
barplot(seq_along(a), col=a, main="original")
# transform to rgb
a1 <- col2rgb(a)
# transform to HSV space
a2 <- rgb2hsv(a1)
# you can try different scaling values e.g. between 0.3 - 0.6
n <- 0.4
barplot(seq_along(a), col=hsv(a2[1,], a2[2,]*n, a2[3,]), main="Pastel_hsv")
# calculate hue for HCl
hue <- a2["h",]*360
# create color with suitable chroma and luminance to get pastel color
a3 <- hcl(hue, 35, 85)
barplot(seq_along(a), col=a3, main="Pastel_hcl")