【问题标题】:R Image Colorbreak & colorsR 图像分色和颜色
【发布时间】:2013-03-15 02:00:32
【问题描述】:

在 R 图像中,我试图更改中断和颜色,当我的图像值高于 20 时,它必须保持红色。 (在我目前的情况下它变成白色)

  colors <- colorpanel(30, "green","red")
  colbreaks <- seq(1,20, length=length(colors)+1)

使用 gplot 中的颜色面板来使用绿色和红色。 我的值大多是 1-15,有时高于 20,但因为我想保持差异可见,所以我想限制 20。在我的脚本中,当值为 21 或更高时,正方形变为白色。我怎样才能抓住它,让它保持红色? 重现:

test123 <- structure(c(2,7,3,18,22,25,12,1), .Dim = c(2L,4L))  
colors <- colorpanel(30, "green","red")  
colbreaks <- seq(1,20, length=length(colors)+1)
image(test123, col=colors, breaks=colbreaks)

图像中的两个白色方块的值是 22 和 25。

【问题讨论】:

    标签: image r colors


    【解决方案1】:

    您还需要定义最后一个断点 (25)。这应该有效:

    test123 <- structure(c(2,7,3,18,22,25,12,1), .Dim = c(2L,4L))  
    colors <- colorpanel(20, "green","red")  
    colbreaks <- c(seq(1,20, length=length(colors)),max(test123)) #add the last point
    image(test123, col=colors, breaks=colbreaks)
    

    这里 20 到 max(test123) 之间的所有内容都用相同的颜色着色(最后一个值来自 colors)。

    【讨论】:

    • 谢谢,我使用了静态值而不是值的最大值,并且让它工作了!谢谢
    猜你喜欢
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 2012-10-28
    • 2019-01-28
    • 2018-07-21
    相关资源
    最近更新 更多