简体   繁体   中英

R: Plotting specific values in raster using different colour

How do I make only those raster cells white that are equal to zero ?

library(raster)
r <- raster(ncol=5, nrow=5)
val<- c(0,0,0.01,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,
    0.85,0.9,0.95,1.0,1.2,1.3,1.63)
values(r) <- val
plot(r, col=c("gray","green","red","orange"), 
        breaks=c(0.1,0.4,0.8,1.2,1.63))
text(r, digits=2)

在此处输入图片说明

You had one more color than breaks, but otherwise, it seems to works all right:

library(raster)
r <- raster(ncol=5, nrow=5)
values(r) <- sort(runif(ncell(r), 0, 1.5))
plot(r, col=c("gray","green","red","orange","blue"), 
     breaks=c(0,0.1,0.4,0.8,1.2,1.63))
text(r, digits=2)

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