Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visualize a list of colors/palette in R

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

> ddf
       r     g     b
1  0.374 0.183 0.528
2  0.374 0.905 0.337
3  0.051 0.662 0.028
4  0.096 0.706 0.898
5  0.876 0.461 0.628
6  0.415 0.845 0.286
7  0.596 0.070 0.523
8  0.724 0.101 0.673
9  0.847 0.434 0.937
10 0.588 0.885 0.604
11 0.481 0.366 0.337
12 0.142 0.075 0.276
13 0.819 0.737 0.658
14 0.910 0.722 0.979
15 0.969 0.012 0.451
16 0.887 0.536 0.123
17 0.432 0.967 0.446
18 0.927 0.125 0.332
19 0.381 0.646 0.656
20 0.040 0.898 0.798
> 
> dput(ddf)
structure(list(r = c(0.374, 0.374, 0.051, 0.096, 0.876, 0.415, 
0.596, 0.724, 0.847, 0.588, 0.481, 0.142, 0.819, 0.91, 0.969, 
0.887, 0.432, 0.927, 0.381, 0.04), g = c(0.183, 0.905, 0.662, 
0.706, 0.461, 0.845, 0.07, 0.101, 0.434, 0.885, 0.366, 0.075, 
0.737, 0.722, 0.012, 0.536, 0.967, 0.125, 0.646, 0.898), b = c(0.528, 
0.337, 0.028, 0.898, 0.628, 0.286, 0.523, 0.673, 0.937, 0.604, 
0.337, 0.276, 0.658, 0.979, 0.451, 0.123, 0.446, 0.332, 0.656, 
0.798)), .Names = c("r", "g", "b"), class = "data.frame", row.names = c(NA, 
-20L))

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)) 
like image 383
rnso Avatar asked Sep 08 '14 14:09

rnso


People also ask

How do I display colors 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.

Which command is used to show built in colors in R?

R can interpret hundreds of named colors, such as "plum" , "seagreen2" , and "peachpuff3" as hexadecimal colors. To see a list of the named colors (just the names, not the colors themselves) use the command colors() .

Which R package can we use to add compelling color schemes to our visualizations?

The R package ggsci contains a collection of high-quality color palettes inspired by colors used in scientific journals, data visualization libraries, and more.

How many colors does R have?

R has 657 built in color names To see a list of names: colors() These colors are displayed on P. 3. Finding a good color scheme for presenting data can be challenging.


1 Answers

I think the simplest option is scales. This also has the advantage of showing the hex values in the colours.

library(scales)
pal <- rgb(ddf$r, ddf$g, ddf$b)
show_col(pal)

enter image description here

like image 90
Matt_B Avatar answered Sep 25 '22 11:09

Matt_B