我已经收到一个.tif文件,其中包含有关每个值的颜色信息(例如,森林是绿色的,云是黑色的).qml文件。levelplot绘制错误的分类颜色
library(raster)
library(rasterVis)
sm <- raster("UT_classification_coded.tif")
########## Classify raster/build attribute table
sm <- ratify(sm)
rat_sm <-levels(sm)[[1]]
# Create categories
rat_sm$landcover <- c('Forest', 'Active vegetation', 'Senescent vegetation', 'Disturbed', 'Rice flooded', 'Rice growing', 'Settlement', 'Water', 'Cloud', 'Cloud shadow', 'Forest')
levels(sm) <- rat_sm
##### plot the colours using the .qml file
levelplot(sm, col.regions=c("#00b144", "#00ff00", "#ffc0a0", "#00ebeb", "#86b1ec", "#de57ff", "#ffff00", "#0000ff", "#000000", "#000000", "#008000"), xlab=NULL, ylab=NULL, scales=list(draw=FALSE), maxpixels=6e6)
的问题是,levelplot
“相信”,土地利用类别(森林,稻水淹没等)都在相反的字母顺序,等等都是颜色。因此颜色被分配到错误的类别。例如,最后三种颜色(“#000000”,“#000000”,“#008000”)被分配给水,沉降,景物植被。
感谢任何建议,以解决这个问题(除了绘制反向字母顺序的颜色,这是乏味的,因为这不是如何.qml文件呈现信息)。
编辑:这里的.tif文件
class : RasterLayer
dimensions : 10981, 10981, 120582361 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : 299993, 409803, 9190235, 9300045 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=18 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : C:\Users\Documents\UT_classification_coded.tif
names : UT_classification_coded
values : 1, 15 (min, max)
参见:https://github.com/oscarperpinan/rastervis/issues/26#issuecomment-335011814 – Matifou