Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert colors to imitate greyscale printing

Tags:

r

colors

graphics

When reading this question, I started to think whether it would be possible to convert colors to imitate an average greyscale printer (assuming that your screen is calibrated)? Finding an approvable approximation would save paper.

For example, how to convert these colors to see whether the light and dark blues and reds can be differentiated on paper?

temp <- rgb2hsv(239, 138, 98, maxColorValue=255)
Rl <- hsv(h = temp[1,], s = 0.5, v = 1)
Rd <- hsv(h = temp[1,], s = 0.5, v = 0.4)
temp <- rgb2hsv(103, 169, 207, maxColorValue=255)
Cl <- hsv(h = temp[1,], s = temp[2,], v = 1)
Cd <- hsv(h = temp[1,], s = temp[2,], v = 0.4)

plot(1:4, type = "p", col = c(Rl, Rd, Cl, Cd), pch = 19, cex = 8, xlim = c(0,5), ylim = c(0,5))

enter image description here

like image 771
Mikko Avatar asked Oct 28 '25 18:10

Mikko


1 Answers

Use an HCL palette with chroma set to zero to create greyscale values that are indistinguishable to the human eye.

library(colorspace)
n <- 10
cols <- rainbow_hcl(n)
plot(seq_len(n), cex = 5, pch = 20, col = cols)

greys <- rainbow_hcl(n, c = 0)
plot(seq_len(n), cex = 5, pch = 20, col = greys)

If you want to generate the greys from your original colours, use the scales package.

library(scales)
greys2 <- col2hcl(cols, c = 0)
plot(seq_len(n), cex = 5, pch = 20, col = greys2)
like image 57
Richie Cotton Avatar answered Oct 31 '25 08:10

Richie Cotton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!