R:使用不同颜色在栅格中绘制特定值

时间:2017-12-01 13:08:25

标签: r plot colors raster

如何仅将那些栅格单元格设为白色等于零?

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)

enter image description here

1 个答案:

答案 0 :(得分:1)

你还有一种颜色而不是休息,但除此之外,它似乎可以正常运作:

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)