title: Vary colors of axis labels in R based on another variable
body: <p>I usually use ggplot2, but in this case I am using the regular <code>image()</code> function to plot a heatmap of a large data set. I can label <em>all</em> the labels as red, but I want to label the y-axis with text of different colors based on a vector of color definitions that I generate:</p>
  
  <pre><code>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 works but isn't the colors I want
  axis(2,at=1:length(labs),labels=labs,las=2, adj=1,cex.axis=0.6,col.axis="red")
  </code></pre>
  
  <p>That generates the following image:</p>
  
  <p><img src="https://i.stack.imgur.com/HirT8.png" alt="Example plot"></p>
  
  <p>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...</p>
  
  <pre><code>axiscolors = c("black","red","black")
  axis(2,at=1:length(labs),labels=labs,las=2, adj=1, cex.axis=0.6, col.axis=axiscolors)
  </code></pre>
  
  <p>This is the effect I am after with some "real" data...</p>
  
  <p><img src="https://i.stack.imgur.com/QD2nD.png" alt="actual heatmap"></p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>As a back-up, if this is possible in ggplot2, I might be willing to re-factor my code. There are a couple other applications I would use this for as well. </p>
  
  <p>I figured out a way to plot a layer of red symbols over the top of the old labels, but would prefer a native method with the color vector, if possible... </p>
  
  <pre><code>sublabs = c("B")
  axis(2,at=match(sublabs,labs),labels=sublabs,las=2, adj=1, cex.axis=0.6, col.axis="red")
  </code></pre>
  
  <p>Another way would be to use <code>text()</code> if I could put the labels outside the plot space...</p>
  
  <pre><code>text(c(1,1,1),c(1,2,3),labs,col=c("black","red","black"))
  </code></pre>
  
  <p><strong>UPDATE:</strong> See below for a solution that works with <code>ggplot2</code>...</p>