1

我正在尝试绘制此光栅文件的图像。图例的颜色是这样的:低值用红色,高值用绿色。

但通常红色与高值相关联。这就是为什么我用来rev反转图例的颜色。但是我得到了一些不同的东西。是否有另一个功能可以反转图例的颜色并保持颜色不变。

require(raster)
require(fields)
r = raster(y)
extent(r) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90))
plot(r, col = rainbow(20, s = 1, v = 1, start = 0, 
     end = 1),lab.breaks=seq(0,0.6,0.05),
     breaks=seq(0,0.6,0.05), zlim=c(0.0,0.6),horizontal = TRUE, 
     xlab="Longitude", ylab="Latitude",legend.shrink = 0.9,
     legend.width = 1.2)

然后我用这个给了我:

plot(r, col = rev(rainbow(20, s = 1, v = 1, start = 0, end = 1)),
     lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
     zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude", 
     ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)
4

1 回答 1

4

显然你没有检查颜色。

> length(rainbow(20, s = 1, v = 1, start = 0, end = 1))
[1] 20

但并非全部使用了 20 个,您只使用了其中的 12 个,所以:

plot(r, col = rev(rainbow(20, s = 1, v = 1, start = 0, end = 1)[1:12]),
     lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
     zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude", 
     ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)

应该给你你想要的情节。毕竟,你有 13 个中断值,所以只有 12 个类别。这意味着您可以这样做:

plot(r, col = rev(rainbow(12, s = 1, v = 1, start = 0, end = 1)),
     lab.breaks=seq(0,0.6,0.05),breaks=seq(0,0.6,0.05),
     zlim=c(0.0,0.6),horizontal = TRUE, xlab="Longitude", 
     ylab="Latitude",legend.shrink = 0.9,legend.width = 1.2)
于 2013-01-30T15:14:56.387 回答