I was hoping to use levelplot to produce a set of maps using a large raster
with many attributes in the RAT.

I was expecting that levelplot would produce a legend in which the each
level of the attribute used in the plot was listed once ( and associated
with a single color in the legend).

However levelplot is resulting in one level in the legend for each of the
RAT IDs.

Additionally where the attribute had NA values I expected that these would
result in a the corresponding cells appearing blank (as NA values in the
original raster did) however a color is assigned to the "NA" from the
attribute table and it appears in the legend, but the NA cells in the
raster istself remain blank.

Is there any way to get levelplot to produce colors, and legend with one
value for each level in the selected attribute?

the trivial code shows what is happening and has a manually produced
version  showing what I expected

thanks



require(raster)
require(rasterVis)
require(gridExtra)
M<-matrix(1:4,4,4)
M[2:3,2:3]<-NA
R<-raster(M)
R<-ratify (R)
R@data@attributes[[1]]$alpha<-c("a","b","a","c")
R@data@attributes[[1]]$alphakey<-c(1,2,1,3)
R@data@attributes[[1]]$HasNA<-c(1,2,NA,1)

p1<-levelplot(R,att="alpha",main="a appears twice on legend \n and in
different colours")
p2<-levelplot(R,att="alphakey",main="alphakey")
p3<-levelplot(R,att="HasNA",main="HasNA")


# in this trivial example I can obtain the desired result using reclassify,
the real example contains many attributes calcualted based on combinations
fo attributes
#Ideally I would like to avoid reclass on each attribute - the actual
raster has 30 columns of attributes withfor a several million cell raster.
RC<-reclassify(R,R@data@attributes[[1]][,c(1,3)])
RC<-ratify(RC)
RC@data@attributes[[1]]$alpha<-c("a","b","c")
p4<-levelplot(RC,att="alpha", main="This was what I expected")
grid.arrange(p1,p2,p3,p4,nrow=2, ncol=2)

	[[alternative HTML version deleted]]

