简体   繁体   中英

controlling raster plot legend labels to display specified breaks value in r

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.

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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM