0

I have a rasterstack

class      : RasterStack 
dimensions : 47, 89, 4183, 6  (nrow, ncol, ncell, nlayers)
resolution : 0.5, 0.5  (x, y)
extent     : 60.75, 105.25, 15.75, 39.25  (xmin, xmax, ymin, ymax)
crs        : NA 
names      :    VegC.1,   layer.1,    VegC.2,   layer.2,    VegC.3,   layer.3 
min values :   0.00000, -11.52596,   0.00000, -11.51896,   0.00000, -11.49996 
max values :  21.14100,  16.52118,  18.85200,  16.69225,  23.08900,  20.25300 

I plot the stack with same color scheme. However I want the 0 value to be white. i use the colorscheme

cols <- inlmisc::GetColors(scheme = "BuRd",n = 256)

But the plot shows blue on the zero value. Is there an easy way for fixing color scale for raster stacks?

Hallie Sheikh
  • 381
  • 3
  • 12

1 Answers1

0

I answer based on the following assumptions:

  • You are using the raster package
  • You are using the plot() function of the raster package to generate the plot

(next time, please indicate both the packages and the functions you are using, and even better, provide code with a reproducible example --it doesn't have to be based on your data, just a small dataset that you can use to show your problem)

Most of the times your (very natural!) wish of mapping the zero value to the middle of the palette --even if the data are not symmetric around zero-- is fulfilled by using a parameter in the plotting function. See for instance this post on the pheatmap() function where the breaks parameter is used: Set 0-point for pheatmap in R

That said, from the documentation of the plot() function of the raster package we see that it accepts a ... parameter which can receive any parameter that is accepted by the image.plot() function of the fields package, as indicated in the Details section of the plot() function:

Details
Most of the code for the plot function for a single Raster* object was taken from image.plot (fields package).")

In the documentation of the image.plot() function of the fields package we read:

breaks Break points in sorted order to indicate the intervals for assigning the colors. Note that if there are nlevel colors there should be (nlevel+1) breakpoints. If breaks is not specified (nlevel+1) equally spaced breaks are created where the first and last bin have their midpoints at the minimum and maximum values in z or at zlim

You can read the answer for Set 0-point for pheatmap in R on how to set the breaks so that the 0 value is mapped to the middle of the color palette you chose (i.e. white).

Note: I cannot give you a working example because I don't have the raster package installed.

mastropi
  • 1,354
  • 1
  • 10
  • 14