3

Is it possible to draw a color matrix using levelplot function in the R package lattice? I must color each cell with an RGB function.

The color matrix must be like below and i need to color each cell like rgb(1,0.8,0.9) etc..

Color matrix

I need this because i have to implement self-organizing-map algorithm for color classification. i am not allowed to use built-in kohonen/som functions or som classes.

trood
  • 121
  • 1
  • 6

2 Answers2

1

Have look at Murrel: (2011) Raster Images in R Graphics

It gives an excellent explanation how to do such things in base R or in grid.

cbeleites unhappy with SX
  • 13,717
  • 5
  • 45
  • 57
0

This shows you how the rgb colors are encoded in the result from rainbow() and how levelplot will handle that argument to col.regions:

str(  rainbow(100)) 
# chr [1:100] "#FF0000FF" "#FF0F00FF" "#FF1F00FF" "#FF2E00FF" "#FF3D00FF" ...

The red, green and blue arguments range across 0 to FF and the transparency value is FF, so this produces a single band across the range of values:

levelplot(matrix(1:100, 100), region=TRUE, col.regions=rainbow(100) )

And this gives you a (horrible) color matrix:

levelplot(matrix(1:10000, 100), region=TRUE, col.regions=rainbow(100) )
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • can i change the color of a random cell with this approach? i mean i want to change the color of [3,3] – trood Nov 17 '12 at 07:02