Question: I'm producing a heat map with the function image():

```
testmatrix <- matrix(rnorm(100), nrow=10)
image(1:10,1:10,testmatrix)

```

[![enter image description here](https://i.stack.imgur.com/liCFV.png)](https://i.stack.imgur.com/liCFV.png)

I need each cell to display the value inside them, but so far haven't found a way to do it. This functionality doesn't seem to be integrated in the function itself. Is there a way to do this?

(I know heatmap() could do this more straightforwardly, but I am forced to use image() to later integrate the code into another function.)

Answer: 
[Reshape the matrix](https://stackoverflow.com/q/15885111/680068), then use *text*:

```
#reproducible data
set.seed(1); testmatrix <- matrix(rnorm(100), nrow=10)

# convert matrix into 3 column dataframe, x, y, and label
txt <- as.data.frame(as.table(testmatrix))

# then plot text after image function
image(1:10,1:10,testmatrix)
with(txt, text(Var1, Var2, round(Freq, 2)))

```

[![enter image description here](https://i.stack.imgur.com/jG6Hg.png)](https://i.stack.imgur.com/jG6Hg.png)
You can use `row(testmatrix)` and `col(testmatrix)` as `x` and `y` arguments when calling `text`

```r
testmatrix <- matrix(rnorm(100), nrow=10)
image(1:10,1:10,testmatrix)

text(x = row(testmatrix),
     y = col(testmatrix),
     label = sprintf("%.2f", testmatrix))

```

[![enter image description here](https://i.stack.imgur.com/vlA7B.png)](https://i.stack.imgur.com/vlA7B.png)