简体   繁体   English

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

[英]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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在R中以特定颜色绘制栅格以获取特定值 - Plotting a raster in R with specific colors for specific values 使用 R 光栅交互式绘图:鼠标悬停时的值 - Interactive plotting with R raster: values on mouseover 使用R中的自定义颜色绘制光栅图像 - Plotting raster images using custom colours in R 为什么在使用R-package Raster绘制带有“ image(x,y,z)”和“ plot(raster)”的NetCDF层时得到不同的结果? - Why do I get different results in plotting a NetCDF layer with “image(x,y,z)” and “plot (raster)” using R-package Raster? 用R中的阈值绘制栅格 - Plotting raster with thresholds in R 在 R 中绘制 GeoTIFF 栅格 - Plotting a GeoTIFF raster in R 如何在R中给栅格中的特定数字一个不同的颜色(或形状)? - How give certain number in a raster a different colour (or shape) in R? 使用r和ggplot如何指定特定的十六进制颜色/颜色值来表示不同的字符值 - Using r and ggplot How do I specify specific hexadecimal color/colour values to use to represent different character values 将比例大小的点绘制到R中的栅格图上的值 - Plotting points with proporcional sizes to the values over a raster map in R R 中的 function 用于在多个栅格数据中绘制具有一致高值的位置 - A function in R for plotting locations with consistent high values in multiple raster data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM