我有 4 个rasters
值,其值跨越正负尺度。对于 4 : 1) 我只想在 +/-20 范围之外的所有值的rasters
两端使用一种颜色中断,比如说。colorkey
这是因为我对较小值的栅格内和栅格间可变性更感兴趣。
2)我怎样才能指定colorkey
它们看起来类似于的标签:at=c(<=-20, -10, 0 , 10 , >=20)
. 这里最重要的是如何在colorkey
标签中包含不等号
可重现的示例和示例代码如下所示。该图像显示了我使用levelplot
函数显示的实际数据。
library(raster)
library (colorRamps)
set.seed(100)
ras <- raster(ncol=100, nrow=100)
ras1 <- setValues(ras, (1:ncell(ras))/100 + rnorm(ncell(ras)) - 50)
s=stack(ras1,ras1,ras1,ras1)
color_levels=14 #the number of colors to use
max_abolute_value=max(abs(c(cellStats(s, min), cellStats(s, max)))) #what is the maximum absolute value of raster?
color_sequence=unique(round(seq(-max_abolute_value,max_abolute_value,length.out=color_levels+1),0))
myColorkey <- list(at=color_sequence,space = "bottom", ## where the colors change
labels=list(axis.line = list(col = NA),at=color_sequence,rot=0,cex=0.9,font=6,
fontface=1),height=1,width=1.4)
col1 <- colorRampPalette(c("darkred", "red3","red",
"gray96", "lightskyblue", "royalblue3",
"darkblue"))
levelplot(s,contour=F, layout=c(4, 3), col.regions = col1,colorkey=myColorkey,margin=FALSE,xlab=NULL,ylab=NULL,par.strip.text=list(cex=0))