How to set up step color regions?

孤街浪徒 提交于 2020-01-06 04:28:10

问题


With levelplot/spplot we can use at to define the color region range (min, max, interval). My question is: how can I use red for values greater than 29.5?

This is my sample NCDF file --> 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))


回答1:


You have to include the maximum value in the vector of break values, and define the palette accordingly:

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))



来源:https://stackoverflow.com/questions/36840734/how-to-set-up-step-color-regions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!