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..
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.
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.
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) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With