Question

I would like to hide some breaks value in the legend labels only displaying some specified value like min value or maxvalue.

library(raster)
r1 <- r2 <- r3 <- raster(ncol=10, nrow=10)
r1[] <- runif(ncell(r1))
n<-10
brks<-seq(minValue(r1),maxValue(r1),0.05)
plot(r1,breaks=brks,col=gray(seq(0,1,length=n)) )

The length of brks is 20, but I want to hide some values of brks in the legend labels and keep colors divided by brks.

Questions:

  1. How to display minvalue and maxvalue and hide the other value ?(same as strech render in arcmap )

  2. How to display some specified value ? Pls make sure the brks is still working.

Was it helpful?

Solution

The plot method for raster objects takes an argument axis.args which gives you some control over the color table's annotation.

With your data, do something like this (and for more see the "Example" section of the help page returned by help("plot", package="raster"):

## Find the min and max z-values
rng <- range(r1[])

## Construct a list of arguments to be used for the color table
arg <- list(at=rng, labels=round(rng, 4))

## Pass them in to your call to plot
plot(r1,breaks=brks,col=gray(seq(0,1,length=n)), axis.args=arg)

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top