A function imagecan do this, just set the transparency of the second set of colors and overlay it with add=TRUE. Any missing values will be completely transparent, and you can set the alpha level for other colors (of course, your graphics device must support partial transparency for this to work). Here is a quick example:
A <- t(volcano)[ncol(volcano):1,]
B <- (A>160) * rnorm(prod(dim(A)) )
B[ A < 120 ] <- NA
image(A, col=grey( seq(0,1,length.out=12) ) )
hc <- sub('FF$','77',heat.colors(12))
image(B, add=TRUE, col=hc)
source
share