I got a question about how to assign color value in image() function. I thought the col option works as a vector with the same length of Z, with color of each cell in the matrix Z corresponding to the values in. However, it confused me with different result.
To make my question simple, let's say I want to make a color image for a vector x=1:4 with corresponding color for each cell.
image(1,1:length(x), matrix(x, nrow=1, ncol=length(x)), col=c("blue","red",'green','yellow')
The output image looks like this:
However, if I use a different x, say
x=c(3,1,2,1) image(1,1:length(x), matrix(x, nrow=1, ncol=length(x)), col=c("blue","red",'green','yellow'))
I expected the color (from bottom to up) order should be green-->blue-->red-->blue, however, I got a very different order:
I guess I misunderstand how to use the color option in the function. Can someone please help to advise? Thanks