Good day all,
I can't seem to wrap my head around why this is not working. Below are two
examples of plotting a categorical raster. The first has a continuous
series of integers (i.e. 1,2,3) whereas the second has breaks (i.e. 1,3,5).
The legend in the second levelplot example is incorrect as it seems to be
expecting a continuous series. I have very good reasons to have a broken
series and would very much like to have to avoid recoding the to a
continuous series.
Any suggestions would be greatly appreciated. Thanks in advance.
Examples below.
## Example 1
library(raster)
library(rasterVis)
## Categorical data
r <- raster(nrow=10, ncol=10)
r[] = 1
r[51:100] = 2
r[3:6, 1:5] = 3
r <- ratify(r)
rat <- levels(r)[[1]]
rat$landcover <- c('Pine', 'Oak', 'Meadow')
levels(r) <- rat
r
levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1'))
## Example 2
## Categorical data
r <- raster(nrow=10, ncol=10)
r[] = 1
r[51:100] = 3
r[3:6, 1:5] = 5
r <- ratify(r)
rat <- levels(r)[[1]]
rat$landcover <- c('Pine', 'Oak', 'Meadow')
levels(r) <- rat
r
levelplot(r, col.regions=c('palegreen', 'midnightblue', 'indianred1'))