如何设置步进色域?

How to set up step color regions?

levelplot/spplot我们可以用at来定义颜色区域范围(min,max,interval)。我的问题是:如何对大于 29.5 的值使用红色?

这是我的示例 NCDF 文件 --> download here

 library (raster)
 r <- brick('bali.nc', varname='TEMPERATURE', level=1)

 library(rasterVis)
 jet <- colorRampPalette(
   c('#00007F', 'blue', '#007FFF', 'cyan', 'yellow', '#FF7F00', 'red', '#7F0000')
 )

 # First Figure - without at
 levelplot(r, layer=1, margin=F, contour=F, col.regions=jet)

 # Second Figure - with at
 levelplot(r, layer=1, margin=F, contour=F, col.regions=jet, at=seq(27.5, 29.5, 0.1))

您必须在中断值向量中包含最大值,并相应地定义调色板:

rMax <- cellStats(r, max)
myAt <- c(seq(27.5, 29.5, 0.1), rMax[1])
myPal <- jet(length(myAt) - 1)

levelplot(r, layer = 1, margin = FALSE,
          at = myAt,
          par.settings = rasterTheme(myPal))