I usually use ggplot2, but in this case I use the regular image() function to build a heat map of a large dataset. I can mark all the labels as red, but I want to mark the y axis with text of different colors based on the vector of the color definitions that I generate:
grid = structure(c(1:12),.Dim = c(4,3)) labs = c("A","B","C") image(1:4,1:3,grid,axes=FALSE, xlab="", ylab = "")
This generates the following image:

I would like labels A and C to be black and B to be red. This is what I tried, but it gives a "wrong length" error ...
axiscolors = c("black","red","black") axis(2,at=1:length(labs),labels=labs,las=2, adj=1, cex.axis=0.6, col.axis=axiscolors)
This is the effect that I get after some "real" data ...

EDIT:
As a backup, if possible in ggplot2, I might want to change the code coefficient. There are several more applications that I would use for this.
I figured out a way to build a layer of red characters on top of the old shortcuts, but, if possible, would prefer my own method with a color vector ...
sublabs = c("B") axis(2,at=match(sublabs,labs),labels=sublabs,las=2, adj=1, cex.axis=0.6, col.axis="red")
Another way would be to use text() if I could put labels outside the bounds of space ...
text(c(1,1,1),c(1,2,3),labs,col=c("black","red","black"))
UPDATE: Below is a solution that works with ggplot2 ...