HI,

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.

```r
x=1:4
image(1,1:length(x), matrix(x, nrow=1, ncol=length(x)), col=c("blue","red",'green','yellow'))
```

The output image looks like this:

![output image 1][1]

However, if I use a different x, say

```r
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:

![output image 2][2]

I guess I misunderstand how to use the color option in the function. Can someone please help to advise? Thanks

-Xianjun

 [1]: https://www.dropbox.com/s/vzzt4t8u0nayy85/image1.png?raw=1
 [2]: https://www.dropbox.com/s/g0traftglvtknrg/image2.png?raw=1
OK I figured it out myself:

Unless the breaks is set, the range of Z (or x in above example) is evenly cut into N intervals (where N = the length of color) and values in Z are proportionally assigned to the nearest color.

For example, when `x=c(3,1,2,1)` and `col=c("blue","red",'green','yellow')`, the minimal of x is assigned as the first color, and max to the last color. Any value between is calculated proportionally to a color. In this case, 2 is the the middle one, according to the principal that intervals are closed on the right and open on the left, it's assigned to "red". So, that's why we see the colors are yellow-->blue-->red-->blue.