问题
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