You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
library(rasterVis)
f <- system.file("external/test.grd", package="raster")
r <- round(raster(f))
## assign a color table
## if the original raster (on disk) had a color table it should already be in this slot
r@legend@colortable=rainbow(cellStats(r,max))
str(r)
## use the color table instead. Could write a simple wrapper function for this...
## this might not work for all color tables....
cols=r@legend@colortable
levelplot(r,col.regions=cols,at=0:length(cols))
The text was updated successfully, but these errors were encountered:
It seems there is an additional issue if the argument to col.regions is factor, in which case values get re-ordered according to levels, and hence colours are confused? See code below.
Also, the NA value is the colourtable could be tricky: it seems to be the first colour in the colourtable, but might not be reported by user in the attribute table?
No, sorry. Nowadays I have less time than desired for improvements.
It seems there is an additional issue if the argument to col.regions is factor, in which case values get re-ordered according to levels, and hence colours are confused?
This is a common problem with factors: I wouldn't use them for a palette. You can set stringsAsFactors = FALSE in the data.frame call.
Already implemented in
plot3d
.A simple solution was proposed here
The text was updated successfully, but these errors were encountered: