Convert colors to imitate greyscale printing

后端 未结 4 1388
孤街浪徒
孤街浪徒 2021-01-21 06:07

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)?

4条回答
  •  青春惊慌失措
    2021-01-21 07:01

    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)
    

提交回复
热议问题