【问题标题】:How to set certain values to specific colour in R?如何将某些值设置为 R 中的特定颜色?
【发布时间】:2013-12-20 08:15:20
【问题描述】:

我有一个矩阵 r(光栅)。我想绘制 r ,这可以使用

plot (r)

但我想将所有 20 的值(因此在图例的比例中不会考虑这个值)标记为红色并绘制r 通常如下所示。 一个可重现的例子:

library(raster)
r <- raster(nrows=10, ncols=10)
r <- setValues(r, 1:ncell(r))
plot(r)

这将产生:

【问题讨论】:

    标签: r matrix plot raster


    【解决方案1】:

    优雅不一样,但这是你打算做的吗?

    par(mfrow=c(2,2))
    plot(r)
    r.20 <- calc(r, fun=function(x){ x[x == 20] <- NA; return(x)} )
    as.matrix(r.20)
    plot(r.20)
    r.not20 <- calc(r, fun=function(x){ x[x != 20] <- NA; return(x)} )
    plot(r.not20, col="red")
    plot(r.20);
    par(new=TRUE)
    plot(r.not20, col="red", legend=FALSE)
    

    【讨论】:

      猜你喜欢
      • 2022-10-18
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多