Since color intervals are defined as (*bottom*, *top*] , values in z equal to zlim [1] will be colored with the outer .below.color (because the range of the outer .below.color is ( *zlim[1] - zstep* , *zlim[1]* ] ).
The next version fixes this error:
image.nan.better <- function(z, zlim, col, na.color='gray', outside.below.color='black', outside.above.color='white',...) { zstep <- (zlim[2] - zlim[1]) / length(col);
compare:
f = matrix(abs(rnorm(300)),nrow=50) f[which(f>1)]=1 f[44,4] = 0 f[41,4] = NA f[42,4] = NA f[43,4] = NA f[44,3] = -1 f[44,5] = 2 image(as.matrix(f),col=c('green3','green2','blue1','blue3'),zlim=c(0,1)) image.nan(as.matrix(f),col=c('green3','green2','blue1','blue3'),zlim=c(0,1),outside.below.color='red',outside.above.color='brown',na.color='yellow') image.nan.better(as.matrix(f),col=c('green3','green2','blue1','blue3'),zlim=c(0,1),outside.below.color='red',outside.above.color='brown',na.color='yellow')