The raster package provides the ability to create rasters with a categorical variable, while the rasterVis package includes functions for building them. The ratify function allows the ratify to include a lookup table that associates the basic values โโof the raster integer with other values, which can be characters. This directly allows you to use any other way of value in the levels of a rationalized raster.
Here is an example.
library(rasterVis) r <- raster(xmn = 0, xmx = 1, ymn = 0, ymx = 2, nrow = 10, ncol = 11, crs = as.character(NA)) r[] <- sample(seq_along(letters[1:5]), ncell(r), replace = TRUE)
There are updates to rasterVis that make a workaround unnecessary.
source share