Is there any way to change the color of NA-values in R? I have masked out some values in a raster stack and was wondering, if I can change the color of the masked values from white to e.g. yellow? I am using plotRGB for plotting my masked raster files.
I am not familiar with plotRGB
, but it belongs also to the raster
package with the same function colNA
, which is described in ?colNA
as "color for the background (NA values)"
.
library(raster)
#simulating missing values
tg<-matrix(1:15,nrow=3)
tg[2,3]<-NA
tg[1,5]<-NA
#rasterize
tg_raster<-raster(tg)
#normal plot
plot(tg_raster)
#replace NAs with blue color
plot(tg_raster,colNA="blue")