Trying to map a categorical raster using levelplot in R, but the legend is always showing the numeric IDs as opposed to the categorical classes. See example below. Anyone encounter this issue and know what may be the problem?
library(raster)
library(rasterVis)
r <- raster(ncol=10, nrow=10)
values(r) <- rep(1:4, each=25)
r <- ratify(r)
rat <- levels(r)[[1]]
rat$legend <- c("Class A", "Class B", "Class C", "Class D")
levels(r) <- rat
rasterVis::levelplot(r)
Raster map using levelplot

Somehow with a newer version of
rasterVisthe categorical legend doesn't work (Probably a bug). You could install an older version to get the following result:Created on 2023-01-02 with reprex v2.0.2