Hi all,

I am trying to plot a raster which comes with an attribute table and a colortable using the rasterVis levelplot function.

Here is my first question: is it possible to address the colortable slot directly in the levelplot function (as is possible for the plot3D through the useLegend argument)?

Since I did not find a way to do it, I tried the below. Note that the original attribute table is not arranged as is neccessary for levelplot to read it so I first create a new raster and assign to it the attributes which are needed:


######
r<-raster(##some raster with attribute and colortable##))


ratdf<-as.data.frame(levels(r))

rat<-as.data.frame(ratdf[[5]])

nvec<-as.character(ratdf[[4]])
rat$classes<-nvec

names(rat)<-c("ID","classes")

r1<-raster(r)
r1[]<-r[]


r1<-ratify(r1)
levels(r1)<-rat

cols<-r@legend@colortable
cols<-cols[2:29]

levelplot(r1,col.regions=cols)

######

I know the procedure is improvable but for now I think it should do. The problem: Everything is plotted fine as expected, except that the last two classes of the raster are assigned the same color. Since there are the same number of classes as number of colors I do not really understand why this happens and, strange enough, in the color key all colors are plotted fine with the correct labels....additionally, when i do it using the plot() function it is working fine. When I used a different color ramp for levelplot it worked out for all classes and everything was well differentiated... Is there maybe some hex color code which levelplot can't read? Please appologize if I didn't express clearly what I want but I am still at the beginning of using R.

Thanks a lot in advance!

Greg


	[[alternative HTML version deleted]]

