rcolor-palette

visualize a list of colors/palette in R


I have following data.frame with rgb values. Hence each row indicates a color.

pdf <- read.table(header = TRUE, text = "
r     g     b
0.374 0.183 0.528
0.374 0.905 0.337
0.051 0.662 0.028
0.096 0.706 0.898
0.876 0.461 0.628
0.415 0.845 0.286
0.596 0.07  0.523
0.724 0.101 0.673
0.847 0.434 0.937
0.588 0.885 0.604
0.481 0.366 0.337
0.142 0.075 0.276
0.819 0.737 0.658
0.91  0.722 0.979
0.969 0.012 0.451
0.887 0.536 0.123
0.432 0.967 0.446
0.927 0.125 0.332
0.381 0.646 0.656
0.04  0.898 0.798
")

How can I visualize these colors? This can be either as bars of color or a palette or a pie chart. I tried to use following method but could not fit it in my data:

pie(rep(1,20), col=rainbow(20)) 

Solution

  • image() will work well here if you convert the colors via rgb()

    image(1:nrow(ddf), 1, as.matrix(1:nrow(ddf)), 
          col=rgb(ddf$r, ddf$g, ddf$b),
          xlab="", ylab = "", xaxt = "n", yaxt = "n", bty = "n")
    

    enter image description here