1

在 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。

4

1 回答 1

0

您还需要定义最后一个断点 (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 到 20 之间的所有内容max(test123)都用相同的颜色着色(最后一个值来自colors)。

于 2013-03-25T14:47:24.427 回答