ArcGIS, for example, stretched color scheme in R for Rasters

I am trying to reproduce the stretched color scheme used by ArcGIS to display rasters in R. I want to use a method that defines the min / max of the color scale as mean (raster_values) +/- 2 * sd (raster_values) and then anything outside of this range will be set to min or max colors depending on the inequality.

I don't know how to tell R to display all values ​​above / below the threshold as the max / min color value (it just doesn't color the cells).

#Load libraries
  library(raster)
  library(RColorBrewer)

#Color scale
  bluescale = colorRampPalette(brewer.pal(9,"PuBu"))

#Create raster and plot it 
  x = raster(matrix(rnorm(625,20,5),25,25))
  plot(x,col=bluescale(50),breaks=seq(mean(values(x))-2*sd(values(x)),mean(values(x))+2*sd(values(x)),length.out=51))

      

enter image description here

It does not display all values. How can I achieve this?

+3


source to share


1 answer


How easy it is to widen the gaps for these latter groups

br <- seq(mean(values(x))-2*sd(values(x)),
    mean(values(x))+2*sd(values(x)),length.out=51)
br[1] <- min(values(x));
br[length(br)] <- max(values(x))
plot(x,col=bluescale(50),breaks=br)

      



enter image description here

+3


source







All Articles